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

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -