Re: Warnings from last compilation.
bH wrote:
Hi All,
The program correctly sorts the items in the String array.
.Warnings from last compilation are listed after the compile.
Note: C:\..\SortObjects.java uses unchecked or unsafe operations.
Note: Recompile with -XIint.unchecked for details <<<<
It's -Xlint:unchecked , not -XIint.unchecked
This warning means that you are using generics-capable code without
using it.
List inputList = new ArrayList(Arrays.asList(t)); //
Change to:
List<String> inputList = Arrays.asList(t);
List l = sort(inputList);
List<String> l = sort(inputList)
System.out.println("\nStrings sorted List ...");
for(int i = 0; i < l.size(); i++)
System.out.println((String)l.get(i));
This line is:
System.out.println(l.get(i));
}
public static List sort(List list) {
public static List<String> sort(List<String> list) {
Collections.sort(list, new Comparator() {
Collections.sort(list, new Comparator<String>() {
public int compare(Object o1, Object o2) {
public int compare(String o1, String o2) {
String s1 = (String)o1;
String s2 = (String)o2;
and delete these two lines
[ no more changes in file ]
The Java tutorial on generics, accessible from here:
<http://java.sun.com/j2se/1.5/docs/>
is very helpful. Also review the Javadoc for List, Collections, Arrays,
and Comparator, all accessible from:
<http://java.sun.com/j2se/1.5/docs/api/index.html>
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth