Re: Warn About Raw Types?
Mon, 14 Feb 2011 14:06:35 +1300, /Lawrence D'Oliveiro/:
ldo@theon:java_try> cat test.java
class test
{
public static void main(String[] args)
{
Class s = String.class;
} /*main*/
}
ldo@theon:java_try> javac -Xlint test.java
ldo@theon:java_try> javac -Xlint:deprecation test.java
ldo@theon:java_try> javac -Xlint:all test.java
ldo@theon:java_try>
No warnings.
Any other suggestions?
Trying an example from the "lmgtfy" results [1] given in a reply by
markspace:
import java.util.*;
class test {
public static void main(String[] args) {
ArrayList data = new ArrayList();
data.add("hello");
data.add("world");
Iterator<String> it = data.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
}
}
}
I get:
% javac test.java
Note: test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
% javac test.java -Xlint
test.java:5: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
data.add("hello");
^
test.java:6: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
data.add("world");
^
test.java:9: warning: [unchecked] unchecked conversion
found : java.util.Iterator
required: java.util.Iterator<java.lang.String>
Iterator<String> it = data.iterator();
^
3 warnings
It appears your exact example doesn't make javac emit "unchecked"
warning, while I can see such warning in my Eclipse IDE. It could
be related to the "harmless" nature of your example, as indicated
in the Arved Sandstrom's reply.
[1] http://www.rgagnon.com/javadetails/java-0521.html
--
Stanimir