Reputation:
Using a library with an abstract class A
and interfaces I
and J
, I get the following warning message when I extend / implement the class / interfaces:
Missing type arguments for generic class J<T>.
As a MWE, the classes are as follows (T and S are generic type parameters):
public abstract class A {}
public interface I<T extends A> {
public <S extends T> void doStuff(J<? super S> param);
}
public interface J<T extends A> {
public void doOtherStuff();
}
Here are my classes:
public class AExtended extends A {}
public class IImplemented implements I<AExtended> {
@Override
public void doStuff(J param) {}
}
Explicitly using the class AExtended
as below does not properly implement doStuff() from I
:
public class IImplemented implements I<AExtended> {
@Override
public void doStuff(J<AExtended> param) {}
}
Upvotes: 3
Views: 7883
Reputation: 2920
You're not overriding doStuff
in IImplemented
because the method is not generic and the type bounds are not present. This version of doStuff
should work for you:
public <S extends AExtended> void doStuff(J<? super S> param) {}
Notice that since the type of I
is AExtended
it is used appropriately here, and the lower bound in the wildcard type for J
is also included.
Upvotes: 1
Reputation: 6297
try with:
public class IImplemented implements I<AExtended> {
@Override
public <S extends AExtended> void doStuff(J<? super S> param) {
// ...
}
}
Upvotes: 1