I am new to Java Generics. I have to implement an interface which is of generic type. The syntax is as follows:
public interface A{}
public interface B<T extends A>{
public T methodB(T a) ;
}
Now I have to implement B so Lets say my Class is C
public class C implements B<T extends A>{}
The java compiler is not letting me use it this way. Also I do not want to use raw types. Please help.
It should be
public class C<T extends A> implements B<T>
The type parameter is declared following the class name, and later can be used in the implements clause.
If your implementing class is still a generic type you have to use this syntax:
public class C<T extends A> implements B<T> {}
As explained by Eran.
If C
is not generic you simply need to specify the type argument for your interface:
public class C implements B<TypeExtendingA> {}
Where TypeExtendingA
implements or extends A
(or is A
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With