Immutable Method Java
- by Chris Okyen
In Java, there is the final keyword in lieu of the const keyword in c and c++.
In the latter languages their is mutable and immutable methods such as stated in one answer by Johannes Schaub - litb the question how-many-and-which-are-the-uses-of-const-in-ce
Use const to tell others methods won't change the logical state of this object.
struct SmartPtr {
int getCopies() const { return mCopiesMade; }
}ptr1;
...
int var = ptr.getCopies(); // returns mCopiesMade and is specified that to not modify objects state.
How is this performed in Java?