+ 1
When do you use constants?
I don't know the usage of constants
2 Réponses
+ 2
i agree that it doesn't have daily uses but there is a use for it after all ....
when you have a bunch of values that wouldn't change .....
like days of week . points for tasks ......
+ 1
You might want a particular class to be initialized with some values but then be unable to change. Using final in Java means you can't change it (with some caveats) so that enforces that behavior. If you come back to it after some time or another developer works on your code this also communicates that intention.
You could imagine you made a booking for a holiday - you could allow customers to amend a booking or cancel and make a new booking. Sometimes the latter might be preferable