File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Generics

 
Arsineh Keshishian
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,
its just a DrunkenKathyAndBertWhileWritingBooksError.

Correct line looks like:
public static <E extends Number> List<E> process(List<E> nums)
 
Tarun Kumar
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Arsineh Keshishian
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic