Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generics unchecked assignment  RSS feed

 
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
Posts: 20904
81
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
Boost this thread!