Is this object mutable?
java, mutable
Solution
Of course - if you want it to be immutable, then you need something like:
public class MyObject {
private final int myField;
public MyObject(int f) {
myfield = f;
}
public int getMyField() {
return myField;
}
}
Problem
If I have a class like that: ``` public class MyObject { private int myField = 2; public void setMyField(int f) { this.myField = f; } } ``` Will objects of this class be mutable? Thanks!