Java Generics - implements and extends

generics, java

Solution

When you have interfaces in generics, you still have to use the `extends` keyword.

In your case, if you know what `T` will be :

public class A<T extends C> implements B<T> {}

If you don't and you simply have to implements `B` with a `C` type :

public class A implements B<C> {}

For the second part, once you've defined `I` you can use it as is in your other generic types :

public abstract class M<I extends P> extends R<I> implements Q<I> {}

Resources :

- www.angelikalanger.com - Java Generics FAQs

- Oracle.com - generics tutorial

Problem

I am trying to write something like ``` public class A implements B<T implements C> {} ``` and ``` public abstract class M<I extends P> extends R<I extends P> implements Q<I extends P> {} ``` but I am getting errors like Multiple markers and syntax error on token extends, expected. Please let me know what is the correct way of doing this.

Original source