I'd like to create an interface that has the following methods:
public interface MyInterface {
public Class<X> getClass();
public void handle(X message);
}
Where X has to be the same type in both methods. The reason I need to do this is I'm getting messages that are blobs that need to be casted into the appropriate class (using getClass) and then I'd like to force implementers to implement a handle method that takes the appropriate class (instead of assuming there is one and using reflection to call it).
It seems like the only way to do this is to add a type param to the interface like so:
public interface MyInterface<T> {
...
}
but that is less than ideal because of cascading dependencies that would require specifying that type in various other classes. Any suggestions? Thanks!
MyInterface.java:2: getClass() in MyInterface cannot override getClass() in java.lang.Object; overridden method is final public Class<X> getClass ();^getClassto find the runtime type and then pushing that type into the static type parameter.