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!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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