File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in super keyword in Genrics

 
Arul Prasad
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic