File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
REST with Spring (video course)
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: 'java.util.Set' to 'java.util.Collection <? extends
>'". 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 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: Generics unchecked assignment
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015