Consider the following program:
class Main {//from w w w .ja v a2 s . c om interface Printable {} interface Shape extends Printable {} interface Rectangle extends Shape {} static class C<T> {} static void foo(C<? super Shape> arg) {} public static void main(String []args) { foo(new C<Printable>()); // ONE foo(new C<Shape>()); // TWO foo(new C<Rectangle>()); // THREE foo(new C()); // FOUR } }
Which of the following options are correct?
c)
options a) and b) For the substitution to succeed, the type substituted for the wildcard ? should be Shape or one of its super types.
option c) the type Rectangle is not a super type of Shape, so it results in a compiler error.
option d) the type argument is not provided, meaning that C is a raw type in the expression new C()
.
hence, this will elicit a compiler warning, but not an error.