Content deleted Content added
→Difference from the C++ const type qualifier: elab type qualifier |
|||
Line 132:
Further, because C and C++ expose pointers and references directly, there is a distinction between whether the pointer itself is constant, and whether the data pointed to by the pointer is constant. Applying <code>const</code> to a pointer itself, as in <code>SomeClass * const ptr</code>, means that the contents being referenced can be modified, but the reference itself cannot (without casting). By contrast, when applying const to the referenced data only, as in <code>const SomeClass * ptr</code>, the contents cannot be modified (without casting), but the reference itself can.
Due to casting, 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 non-const reference. Java's final is a strict rule such that it is impossible to compile code that directly breaks or bypasses the final restrictions. Using [[Reflection_(computer_programming)#Java|reflection]], however, it is often possible to still modify final variables. This feature is mostly made us of when [[Serialization|deserializing]] objects with final members.
==References==
|