Why am I getting these 4 warnings from -Xlint and what should I do about them? I'm just starting in Java, so am likely missing something obvious.
import java.util.*;
class CompareGerbils implements Comparator {
public int compare(Object o1, Object o2) {
return ((Gerbil)o2).number() - ((Gerbil)o1).number();
}
}
class Gerbil {
int gerbilNumber;
Gerbil(int gN) {
gerbilNumber = gN;
}
int number() {
return gerbilNumber;
}
}
public class lt {
public static void main(String[] args) {
// I'd like to be able to add both ints and strings to list
ArrayList list = new ArrayList();
//unchecked call warning:
list.add(1);
//unchecked call warning:
list.add("b");
ArrayList<Gerbil> gerbillist = new ArrayList<Gerbil>();
for(int i = 0; i < 5; i++) {
gerbillist.add(new Gerbil(i));
}
//unchecked conversion warning
//unchecked method invocation
Collections.sort(gerbillist, new CompareGerbils());
}
}
EDIT: replies so far have answered the Arraylist declaration. How about the sort warnings at the bottom of the code? thanks