• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Generics : Raw to ? extends objects

 
Ranch Hand
Posts: 53
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I just don't understand this.

List list = new ArrayList(); List <? extends objects> list1 = list; // unchecked conversion warning.

Since object is the highest upper bound in java, i don't see no reasons why the warning is there. Please advice
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No idea, I'd like to know too.

 
Kim Ming Yap
Ranch Hand
Posts: 53
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this ..

List list = new ArrayList();
List <?> list2 = list; // This will not gives unchecked warning.

Basically:
1.raw to <?> and <?> to raw is fine
2a.raw to <? extends objects> warning.
2b.<? extends objects> to raw is fine since raw is the superclass.
3.<?> to <? extends objects> and <? extends objects> to <?> fine

i just don't understand 2a. If raw to <? extends Integer> gives unchecked warning .. i understand since that is not the highest upper bound.
Basically SCJP by Khalid says that raw to BOUNDED or concrete parameterzied type will gives warning. I just dont understand why upper bounded extending objects are not made exception from this rule.

 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic