Re: checking casts
- From: Thomas Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 21:16:03 +0000
Dan Upton wrote:
When trying to compile something I was working on today, I got this error based on a performing a cast:
PuzzleSolver.java:311: warning: [unchecked] unchecked cast found : java.lang.Object required: java.util.Vector<Piece> piecesClone = (Vector<Piece>)pieces.clone();
I know it's a safe cast, but just for the sake of getting javac to leave me alone I tried sticking it in a try...catch block:
The compiler is complaining that that you are casting to Vector<Piece>, but the runtime will not be able to check that the object isn't actually, say Vector<String>.
The easy way around it is to write:
piecesClone = new ArrayList<Piece>(pieces);
Tom Hawtin -- Unemployed English Java programmer http://jroller.com/page/tackline/ .
- Follow-Ups:
- Re: checking casts
- From: Oliver Wong
- Re: checking casts
- References:
- checking casts
- From: Dan Upton
- checking casts
- Prev by Date: Re: Help with Swing threading!
- Next by Date: Re: Using PHP language in Java/JSP files.
- Previous by thread: checking casts
- Next by thread: Re: checking casts
- Index(es):
Relevant Pages
|