Thread View: borland.public.jbuilder.java.language
2 messages
2 total messages
Started by Alan Shiers
Thu, 04 Aug 2005 20:22
dealing with compiler warning
Author: Alan Shiers
Date: Thu, 04 Aug 2005 20:22
Date: Thu, 04 Aug 2005 20:22
43 lines
2322 bytes
2322 bytes
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
Author: Jeroen Wenting
Date: Mon, 08 Aug 2005 12:16
Date: Mon, 08 Aug 2005 12:16
41 lines
2200 bytes
2200 bytes
"Alan Shiers" <ashiers@hfx.eastlink.ca> wrote:
>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).
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads