Immutable Method Java

Posted by Chris Okyen on Programmers See other posts from Programmers or by Chris Okyen
Published on 2012-11-12T01:14:47Z Indexed on 2012/11/12 5:14 UTC
Read the original article Hit count: 336

Filed under:
|
|
|

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?

© Programmers or respective owner

Related posts about java

Related posts about immutable