There are immutable types in Java. And if you pass an immutable object to a method, it won’t be changed after calling that method even if it’s value was changed in that method. I know that all primitives are immutable. And String is immutable too.
I wrote a simple code for checking that functionality in Java and it seems that wrapper classes for primitives are immutable too. Can anybody list all immutable types in java?
There are immutable types in Java. And if you pass an immutable object to
Share
has nothing to do with immutable.
will change the real thing. While
won’t. The difference here is whether you are changing the reference or operating on the object referenced.
String and those wrapper class are called immutable because there is absolutely no member function like
setValuethat could change that object.Hope you understand this. You may comment and ask freely if you have any more doubt.