java - How does adding an unused generic parameter to an interface stop a class implementing it? -
the following code
public interface igiveup { void surrender(list<class> l); } public class giveup implements igiveup { @override public void surrender(list<class> l) {} } compiles fine. when add unused generic type parameter interface
public interface igiveup<x> { void surrender(list<class> l); } it fails compile (javac 1.6.0_23)
igiveup.giveup not abstract , not override abstract method surrender(java.util.list) it compile if either specify generic in implementation
public class giveup implements igiveup<object> or make method parameter list of not generic type
void surrender(list l);
your class trying implement raw type igiveup - raw type doesn't know generics, method signature after type erasure just:
void surrender(list l) it doesn't matter method parameter didn't use type parameter interface declaration: type erasure removes all traces of generics signatures.
basically, should avoid raw types far possible. more details, follow links above sections of jls, or read java generics faq.
Comments
Post a Comment