Why create a static field for a static property? Isn't it enough just to state that the property is static? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

Why create a static field for a static property? Isn't it enough just to state that the property is static?

1st Apr 2022, 11:13 AM
ā€ŽŲ£Ł†ŲÆŲ±ŁŠŁ‡ā€Ž
ā€ŽŲ£Ł†ŲÆŲ±ŁŠŁ‡ā€Ž - avatar
2 Respostas
+ 2
As I understand it, static members (class bound members) can only make use of other members that are also defined as static.
1st Apr 2022, 1:01 PM
Ipang
+ 1
A static property is a property not a const. The advantage of having a getter and a setter is being able to validate the value before accepting it. You can assign any value to a field. If you have a property you can validate if you want to accept this new value.
2nd Apr 2022, 11:47 AM
sneeze
sneeze - avatar