• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generic Collections

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help understand this question. It is a question at the end of chapter in Kathie Sierra book.

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..........
 
Shashank Rudra
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you should read this...
 
Shashank Rudra
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vijitha for the science. Thanks Ankit for the link.
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And maybe this could also help
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic