A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java SE 8 for the Really Impatient
this week in the
Java in General
Generics unchecked assignment
Joined: Apr 19, 2002
Oct 12, 2007 12:56:00
I'm starting to apply generics to some code.
In this example:
new ArrayList( classroom.getStudentSet() )
The most generic way of using generics is
new ArrayList<Object>( classroom.getStudentSet() )
This causes "Unchecked assignment: '
' to '
>'". Can this warning be resolved without modifying the classroom class?
Joined: Oct 27, 2005
Oct 12, 2007 15:08:00
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.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions
How To Answer Questions
I agree. Here's the link:
subject: Generics unchecked assignment
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014