Board index » jbuilder » dealing with compiler warning

dealing with compiler warning


2005-08-05 04:22:45 AM
jbuilder24
Hi there,
I'm using JDK 1.5 and created an instance of an ArrayList, then after
loading the ArrayList I passed it as an arguement to the
Collections.sort(...) method. When I compile using:
javac -Xlint:unchecked -classpath "C:\Program Files\Apache Softwa
re Foundation\Tomcat 5.5\common\lib\servlet-api.jar;C:\Program Files\Apache
Soft
ware Foundation\Tomcat 5.5\common\lib\jsp-api.jar;C:\Program Files\Apache
Softwa
re Foundation\Tomcat 5.5\webapps\scholastic\WEB-INF\classes;C:\Program
Files\Apa
che Software Foundation\Tomcat
5.5\webapps\scholastic\WEB-INF\classes\mvcs;C:\Pr
ogram Files\Apache Software Foundation\Tomcat
5.5\webapps\scholastic\WEB-INF\cla
sses\com\components;C:\Program Files\Apache Software Foundation\Tomcat
5.5\webap
ps\scholastic\WEB-INF\classes\com\ezjavabeans\ezsmtp;C:\Program Files\Apache
Sof
tware Foundation\Tomcat
5.5\webapps\scholastic\WEB-INF\lib\jasperreports-0.6.7.j
ar" *.java
I got the following warning message:
TestProcessor.java:153: warning: [unchecked] unchecked method invocation:
<T>sor
t(java.util.List<T>) in java.util.Collections is applied to
(java.util.ArrayList
<mvcs.TestProcessor.Answer>)
Collections.sort(list);
^
1 warning
What is it I need to do further to prevent this warning message from popping
up all the time? Am I supposed to ignore it or is there something I'm
expected to do to prevent this warning message?
Please advise,
Alan
 
 

Re:dealing with compiler warning

"Alan Shiers" < XXXX@XXXXX.COM >wrote:
Quote
Hi there,

I got the following warning message:

TestProcessor.java:153: warning: [unchecked] unchecked method invocation:
<T>sor
t(java.util.List<T>) in java.util.Collections is applied to
(java.util.ArrayList
<mvcs.TestProcessor.Answer>)
Collections.sort(list);
^
1 warning

What is it I need to do further to prevent this warning message from popping
up all the time? Am I supposed to ignore it or is there something I'm
expected to do to prevent this warning message?

Please advise,

Alan


Add the annotation @suppresswarnings("unchecked") to the method (or class if you want it to be global for that class) declaration.
E.g. turn
-------------------
public void aMethod(List list) {
Collections.sort(list);
}
-------------------
into
-------------------
@suppresswarnings("unchecked")
public void aMethod(List list) {
Collections.sort(list);
}
-------------------
I'm not fond of annotations, but this is one case they could come in handy (though of course it's like shooting a moquito with an elephant gun as you're potentially hiding warnings you do want to soo).