In a Java program, I have multiple subclasses inheriting from a parent (which is abstract). I wanted to express that every child should have a member that is set once only (
Why not delegate initialization to a method. Then override the method in the parent class.
public class Parent {
public final Object x = getValueOfX();
public Object getValueOfX() {
return y;
}
}
public class Child {
@Override
public Object getValueOfX() {
// whatever ...
}
}
This should allow custom initialization.