Forums Register Login

Doubt in Genrics on super keyword

+Pie Number of slices to send: Send
in Lesson No 7 and for the question no 16 i have a doubt

question was ...

Given a method declared as:

public static <E extends Number> List<? super E> process(List<E> nums)
A programmer wants to use this method like this:

// INSERT DECLARATIONS HERE
output = process(input);
Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow
the code to compile? (Choose all that apply.)

A. ArrayList<Integer> input = null;
ArrayList<Integer> output = null;

B. ArrayList<Integer> input = null;
List<Integer> output = null;

C. ArrayList<Integer> input = null;
List<Number> output = null;

D. List<Number> input = null;
ArrayList<Integer> output = null;

E. List<Number> input = null;
List<Number> output = null;

F. List<Integer> input = null;
List<Integer> output = null;

G. None of the above.

Answer:
B, E, and F are correct.


but i 'm getting the compile error can any aone help me ...


Error ..
------------
TestColl.java:23: incompatible types
found : java.util.List<capture of ? super Base>
required: java.util.List<Base>
List<Base> subList = print(bList);
^
1 error





It was compiled after the change in line 23 as


now i need to know about the correct answer and also the use of the super keyword ....

is there anyone help me
+Pie Number of slices to send: Send
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 691 times.
Similar Threads
doubt abt Generics mock question - from K&B
Generic Collections
doubt in generics........
doubt in super keyword in Genrics
please explain this!!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:18:29.