Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unchecked conversion warning - What is the proper way to fix this?

843793Aug 1 2007 — edited Aug 2 2007
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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2007
Added on Aug 1 2007
6 comments
604 views