ava 1.5 - generics "unchecked cast" suppression

S

Steven Buroff

Is there a way to suppress the "unchecked cast" message for a particular
statement rather than an entire file? There are times when you can't really
avoid the cast. In my case, I'm reading back in a previously serialized
object. I need to cast it. Thanks in advance.

Steve
 
A

Alan Moore

Is there a way to suppress the "unchecked cast" message for a particular
statement rather than an entire file? There are times when you can't really
avoid the cast. In my case, I'm reading back in a previously serialized
object. I need to cast it. Thanks in advance.


Try adding this annotation to the method:

@SuppressWarnings("unchecked")
 
S

Steven Buroff

Alan Moore said:
Never mind: @SuppressWarnings is not implemented in JDK 5.0. Bummer.

Right. Looks like exactly what I was looking for. Thanks for trying.

Steve
 
A

Alan Moore

Right. Looks like exactly what I was looking for. Thanks for trying.

I just wrote a method that's a perfect candidate for this annotation:
the casts are perfectly safe, but the compiler can't know that due to
erasure. I guess I'll go ahead and add the annotation anyway, in the
interest of self-documentation. And maybe someday I'll remember to
quit compiling with the -nowarn option and get a pleasant surprise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top