In C++, I can define an accessor member function that returns the value of (or reference to) a private data member, such that the caller cannot modify that private
This does not exist in java. final
and const
have different semantics, except when applied to a variable of a primitive type. The java solution typically involves creating immutable classes - where objects are initialized in construction and provide no accessors allowing change. Example of such classes would be e.g. String
or Integer
.