Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics unchecked assignment

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm starting to apply generics to some code.

In this example:

The most generic way of using generics is


This causes "Unchecked assignment: 'java.util.Set' to 'java.util.Collection <? extends java.lang.Object>'". Can this warning be resolved without modifying the classroom class?
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If classroom.getStudentSet() returns just a Set, without generics, then no. The only thing to do is either change the classroom class, or use @SuppressWarnings("unchecked") on that variable or the method/constructor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic