File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem with Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem with Generics" Watch "Problem with Generics" New topic
Author

Problem with Generics

Arsineh Keshishian
Greenhorn

Joined: Apr 21, 2008
Posts: 19
Hi guys,

I'm having problem with question 16 in chapter 7(Generics).

Given a method declared as:
public static <E extends Number> List<? super E> process(List<E> nums)

And

// INSERT DECLARATIONS HERE
output = process(input);


Why is the following declaratin wrong?

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



Assumed <E> resolves to <Integer>.
Then the return type List<? super E> could be resovled to List<Number> since Number is the ancestor of Integer.
So what is wrong about this?
Please, I'm not getting this

Thank you very much!
Arsineh
Frank Hinkel
Greenhorn

Joined: Mar 28, 2008
Posts: 24
Howdy,
its just a DrunkenKathyAndBertWhileWritingBooksError.

Correct line looks like:
public static <E extends Number> List<E> process(List<E> nums)
Tarun Kumar
Greenhorn

Joined: Apr 30, 2008
Posts: 26
this problem come earlier also on the forum.
actually it simisprinting.

public static <E extends Number> List<? super E> process(List<E> nums)

it is correctly as
public static <E extends Number> List<E> process(List<E> nums)


Tarun Kumar
Arsineh Keshishian
Greenhorn

Joined: Apr 21, 2008
Posts: 19
Thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Generics