 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Steven Buroff Guest
|
Posted: Tue Feb 22, 2005 7:09 pm Post subject: @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
|
|
| Back to top |
|
 |
Roland Guest
|
Posted: Tue Feb 22, 2005 7:21 pm Post subject: Re: @SuppressWarnings("unchecked") |
|
|
On 22-2-2005 20:09, Steven Buroff wrote:
| Quote: | 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
Doesn't seem to be implemented by javac 1.5.0. |
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4986256>
<http://forum.java.sun.com/thread.jspa?threadID=528421&messageID=3036580>
--
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ /_/ /
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|