Final (Java): Difference between revisions

Content deleted Content added
Tag: section blanking
Tag: section blanking
Line 115:
 
==Difference from the C++ <code>const</code> type qualifier==
 
The C++ parallel to Java's final would be a reference in that once it is initialized, the data being referenced can be changed, but the reference itself can not.
 
Another C++ parallel is <code>SomeClass * const ptr</code> where the contents being referenced can be modified, but the reference itself can not without casting. This is different from the C++ <code>const SomeClass * ptr</code> where the contents cannot be modified without casting, but the reference itself can.
 
C++ const is a soft guideline and it can easily be overridden by the programmer; the programmer can easily cast a const reference to an unconst reference. Java's final is a strict rule such that you can't write a valid code that compiles, breaks or simply bypasses the final restrictions.
 
==External links==