In my most recent class assignment we've been working with generics and I have been receiving this warning:
Note: Selector.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
From what I understand this results from not specifying the type of objects in my collection. I'm currently working with int's for testing purposes, but the program is supposed to allow for sorting of any type object. I don't think I want to specify my collections as int's, and my collection is currently of type T for this reason. But my instructions explicitly state that my program should not generate any warnings. Here is one of my methods:
What I have now:
else {
T[] a = new T[c.size()];
c.toArray(T[] a);
T min = a[0];
for (int i = 0; i < a.size(); i++) {
if (comp.compare(min, a[i]) > 0) {
min = a[i];
}
}
return min;
}
What I'm getting:
Testing.java:48: error: generic array creation
T[] a = c.toArray(new T[c.size()]);