Consider the following example:
public class Sandbox {
public interface Listener {
public void onEvent(T event);
No. You cant. It's because generics are supported only at compiler level. So you can't do thinks like
public interface AnotherInterface {
public void onEvent(List<JPanel> event);
public void onEvent(List<JLabel> event);
}
or implements interface with several parameters.
upd
I think workaround will be like this:
public class Sandbox {
// ....
public final class JPanelEventHandler implements Listener<JPanel> {
AnotherInterface target;
JPanelEventHandler(AnotherInterface target){this.target = target;}
public final void onEvent(JPanel event){
target.onEvent(event);
}
}
///same with JLabel
}
Don't forget that in java generics are implemented using type errasure, yet extension remains after compilation.
So what you are asking the compiler to do (after type erasure is),
public interface AnotherInterface extends Listener, Listener;
which you simply can't do generics or not.