The following code
public class Test {
public static void main(String[] args) {
IBase s = new Sub();
s.remove("String");
}
}
interface IBase<K extends Comparable<? super K>> {
public void remove(K ... keys);
}
class Base<K extends Comparable<? super K>> implements IBase<K> {
public void remove(K... keys) {
System.out.println("removed keys in Base");
}
}
interface ISub extends IBase<String> {
}
class Sub extends Base <String> implements ISub {
public void remove(String... keys) {
System.out.println("removed keys in Sub");
}
throws a ClassCastException
<FONT color=#ff0000 size=1>Exception in thread "main" </FONT><FONT color=#000080 size=1>java.lang.ClassCastException</FONT><FONT color=#ff0000 size=1>: [Ljava.lang.Comparable;
at Sub.remove(</FONT><FONT color=#000080 size=1>Test.java:1</FONT><FONT color=#ff0000 size=1>)
at Test.main(</FONT><FONT color=#000080 size=1>Test.java:5</FONT><FONT color=#ff0000 size=1>)
</FONT>I can't paramatize the IBase s =... as the original code a series of IBase Objects are held in a List<IBase<?>>.
Does anyone have any ideas?