Re:More Dirty Coding Tricks from Game Developers (2010)
by EdwardDiego on Monday August 03, 2015 @05:36AM
(#9994680)
Yep, if you want an immutable list, or whatever, you have to make sure your list is immutable, which usually involves defensive copying.
For built-ins, such as numeric types and "char" (String is obviously disallowed from this definition), final will prevent changes to instances of those types similar to what "const int" does for C++.
For pointers, however, the final keyword in Java limits the ability to change the variable holding the pointer, not to what it references. The equivalent in C++ would be:
Here, the pointer "foo" could not change, but operations changing foo would be allowed.Java (the language) does not possess the semantics to express "the pointer given to a method cannot allow changes to what it points."