Consider the following program:
public class Main { interface Printable {} interface Writable extends Printable {} interface Readable extends Writable {} static class C<T> {} static void foo(C<? super Writable> arg) {} public static void main(String []args) { foo(new C<Printable>()); // ONE foo(new C<Writable>()); // TWO foo(new C<Readable>()); // THREE foo(new C()); // FOUR }/*ww w . j av a 2 s. c o m*/ }
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 Writable or one of its super types.
Option c): The type Readable is not a super type of Writable, 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.