aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generic Collections 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 "Generic Collections " Watch "Generic Collections " New topic
Author

Generic Collections

Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Please help understand this question. It is a question at the end of chapter in Kathie Sierra book.



Programmer Analyst || J2EE web development/design
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Since you are trying to learn, think what the type of input can be (i.e: things can be assigned to -> List<E>) and what the type of the output should be (i.e: to what we can assign a return type of List<? super E>) given <E extends Number> satisfies.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
Hi Giffy,
Welcome to JavaRanch!!!
I think this question is asked before and well discussed............
In fact many questions we ask are mostly already asked..........You should get it if you search this same forum
I'll see if I can get it and post the link if possible..........


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Thanks Guys for the reply. I found the similar post.

Here is a piece that I would like to know how is it happening? Please help me here.

Nikos’ Java blog

Both result in Incompatible types compile error.

If we take q1 as <Number> then q2 can be <Number> too. So will not the assignment be a valid one.

In other case when q1 is <Integer> then q2 can also be <integer>.

I am little lost here so I may be sounding that way.

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Giffy Geraldo wrote:If we take q1 as <Number> then q2 can be <Number> too. So will not the assignment be a valid one.


But will that be always true? If q1 actually refers to an object of generic type LinkedList<Float> (which is perfectly all right) is it possible to assign that object to a reference of type Queue<? super Integer> (which permits only Integer or any super type) ? That's wrong right?

You can think about the other query which can by thought in the same way. Hope you get it
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Maybe you should read this...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Thanks Vijitha for the science. Thanks Ankit for the link.
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
And maybe this could also help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generic Collections