469,366 Members | 2,254 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

@SuppressWarnings("unchecked")

I can't seem to get the @SuppressWarnings("unchecked") to work.
Here is my test program.

public class Tryit {
@SuppressWarnings({"unchecked"})
public <T> T doit(Class<T> clazz){
T val = (T)"xxx";
return val;
}
}

Here is the compiler output:

C:\tmp>javac Tryit.java
Note: Tryit.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

or, with -Xlint:unchecked, I get:

C:\tmp>javac -Xlint:unchecked Tryit.java
Tryit.java:4: warning: [unchecked] unchecked cast
found : java.lang.String
required: T
T val = (T)"xxx";
^
1 warning

Here is the compiler version:

C:\tmp>java -version
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

Other annotations like @override work correctly.
Any idea what I'm doing wrong? Thanks.

Steve Buroff
Jul 17 '05 #1
0 13486

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.