I've been trying to figure this out for awhile now, and I have not seen an example that will set me on the right track. Given the following code:
public TreeSet<String> sort = new TreeSet<String>(CI_NE_Comparator);
public static Comparator CI_NE_Comparator = new CaseInsensitiveNeverEqualsComparator();
public static class CaseInsensitiveNeverEqualsComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
String s1 = (String) o1;
String s2 = (String) o2;
int compare = s1.trim().toLowerCase().compareTo(s2.trim().toLowerCase());
if (compare == 0)
{
return 1; // ensure like values are never deemed equal
}
return compare;
}
}
I'm getting a warning declaring the class variable sort:
Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator <? super String>
So just what is the proper method to make the Comparator conform to generics?
** Btw - if anyone knows of a better way to do that comparator, I'm all ears!