how can a subclass be casted to another subclass with the same superclass? I know that it don’t allow to cast directly from subclass to subclass. Another ways? ID is set into superclass, so it is not nice with making new object; I am using it for state pattern. If the state changes, then the typ of class should change.
@Entity
public class Request() {}
@Entity
public class OpenRequest extends Request() {}
@Entity
public class CloseRequest extends Request() {}
Thanks
This isn’t possible. If you could do this, you could always cast any reference to any other class, since all classes are subclasses of
Object.You will have to create a new instance of the class you want, and transfer the information manually.