While preparing for the SCJP-6 exam I faced with a difficult issue. I can’t find answer by myself. Please, answer for the question and give short comments:
abstract class A<K extends Number> {
// insert code here
}
public abstract <K> A<? extends Number> useMe(A<? super K> k);
public abstract <K> A<? super Number> useMe(A<? extends K> k);
public abstract <K> A<K> useMe(A<K> k);
public abstract <V extends K> A<V> useMe(A<V> k);
public abstract <V super K> A<V> useMe(A<V> k);
public abstract <V extends Character> A<? super V> useMe(A<K> k);
public abstract <V super Character> A<? super V> useMe(A<K> k);
Which method can be inserted in the placeholder above?
P.S. I tried to look on the specification. Those one was not helpful for me.
Answer 1,2,3: The generic type K
shadowed class type K
. In those methods K
is just new generic type. Compiler tries to pass conditional evaluation <K extends Number>
. Method 1,2 passes and 3 - fails.
Answer 4 is completely correct.
Answer 5,7 has syntax error.
Answer 6 incorrect, because test <V extends Number>
will fail.