Cannot compile a class which implements an interface without type parameter?

I think the problem is that if you use raw types anywhere in the class declaration, you're sort of opting out of generics. So this will work - note the parameter change public class MyContainer implements Container { public void addClass(Class clazz) {} } From section 4.8 of the JLS : The superclasses (respectively, superinterfaces) of a raw type are the erasures of the superclasses (superinterfaces) of any of its parameterized invocations I believe that's the relevant bit... the erasure of Container. AddClass(Class clazz) is addClass(Class clazz) But yes, basically unless this is genuine legacy code, you should regard introducing a type parameter into an interface as a breaking change.

I think the problem is that if you use raw types anywhere in the class declaration, you're sort of opting out of generics. So this will work - note the parameter change. Public class MyContainer implements Container { public void addClass(Class clazz) {} } From section 4.8 of the JLS: The superclasses (respectively, superinterfaces) of a raw type are the erasures of the superclasses (superinterfaces) of any of its parameterized invocations.

I believe that's the relevant bit... the erasure of Container. AddClass(Class clazz) is addClass(Class clazz). But yes, basically unless this is genuine legacy code, you should regard introducing a type parameter into an interface as a breaking change.

Skeet- elaboration would be helpful..TIA – hakish Oct 1 '10 at 11:07 I see, thank you Jon. Accepted. – Dale Wijnand Oct 1 '10 at 12:19.

Getting rid if the fixes it: public void addClass(Class clazz) {} The error message is not very descriptive: Name clash: The method addClass(Class) of type MyContainer has the same erasure as addClass(Class) of type Container but does not override it This would mean that both your methods are the same when their types are erased, but the subclass method does not actually implement/override the one from the superclass/interface. This does not make much sense, and I would assume that it's because you have chosen not to use generics in your subclass, you have to stick to that (and not perameterize Class).

If your class uses Generics then a simple solution would be to do this : interface Container { public void addClass(Class clazz); } class MyContainer implements Container { public void addClass(Class clazz) {} } Or if you already know the type of Container you have, class MyContainer implements Container { public void addClass(Class clazz) {} } If your class doesn't use Generics (pre 1.5) then you can't have the part. So there won't be any real problem here. Class MyContainer implements Container { public void addClass(Class clazz) {} }.

Implementing your interface as follows should work (as per type erasure): public class MyContainer implements Container { public void addClass(Class clazz) {} }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions