There is no specific way to do what you want. The only way to have an object, the contents of which cannot be modified, is for that object not to have any "setter" methods. For example, String works that way.
If you want a mutable object, but have the setter methods inaccessible, there are various ways to do it. For example, if the class is in a different package, give the setter methods default scope, so that classes in other packages cannot see them.
Alternatively, create an interface for the getter methods.
Code:
public interface Readable {
public Object getValue();
}
Code:
public class Data implements Readable {
private Object value;
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
Code:
public void doSomething(Readable r) {
// can't change the contents of "r"
Object o = r.getValue();
}
Graham.