If you want your class to be compatible with the plugin with the source class (this means that the client code does not need to change the types of variables), your class must be a subclass of the class that expects the client code. In this case, you cannot hide public variables, although you can easily add getters and setters. However, even if you use a subclass, this will not help if the source class has other subclasses; they will not see those getters and setters.
If you can introduce an unrelated class, then the solution should delegate everything:
public class BetterThing {
private Thing thing;
public BetterThing(Thing thing) {
this.thing = thing;
}
public int getIntProperty1() {
return thing.property1;
}
public void setIntProperty1(int value) {
thing.property1 = value;
}
}
source
share