This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics : Raw to ? extends objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics : Raw to ? extends objects" Watch "Generics : Raw to ? extends objects" New topic

Generics : Raw to ? extends objects

Kim Ming Yap
Ranch Hand

Joined: Dec 17, 2008
Posts: 53

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
Chad Michaels
Ranch Hand

Joined: Jun 25, 2010
Posts: 42
No idea, I'd like to know too.

Kim Ming Yap
Ranch Hand

Joined: Dec 17, 2008
Posts: 53

Try this ..

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

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.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Generics : Raw to ? extends objects
It's not a secret anymore!