wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Generics" Watch "Doubt in Generics" New topic
Author

Doubt in Generics

Lata Bagga
Ranch Hand

Joined: Jun 13, 2007
Posts: 35
Hello Friends,

I have doubt in the following question which is Q no. 16(Chapter 7) from KS & BB of Generics and Collection:



I am not able to understand why option C is not correct. As the return type is List<? super E> and if E is an Integer then List<Number> should work for it.
Can anyone help me with it?

Regards,
Lata
Vitor Isaia
Greenhorn

Joined: Mar 07, 2005
Posts: 12
Both sides (reference and object) need to be of the exaclty same generic type... even if one of the types extends the other one...

So "C" is wrong because the type is different... Number and Integer.
You can't have something like this:
List<Number> l = new ArrayList<Integer>();

Regards,

Vitor
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
This is an errata question, the correct method signature is:

public static <E extends Number> List<E> process(List<E> nums)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Generics
 
Similar Threads
Generics Question
doubt in generics........
doubt abt Generics mock question - from K&B
Doubt in Generics
Doubt in Generics