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!

Question with : "warning: [unchecked] unchecked conversion"

843793Jun 22 2004 — edited Dec 18 2005
Okay, this is the error that I am getting...
.javac -Xlint Tester.java
Tester.java:68: warning: [unchecked] unchecked conversion
found   : java.util.Comparator
required: java.util.Comparator<? super java.lang.String>
    Map <String,Integer> sortedMap = new TreeMap <String,Integer>(comp);
                                                                  ^
1 warning
And now for some background...

I am currently working through the Introduction to Collections Short Course (http://java.sun.com/developer/onlineTraining/collections/index.html) and been able to successfully do all the Collection exercises (magercises) and am having too much fun trying to add all the Generics stuff to make the code compile without errors or warning... Now I am at the Maps section and am currenly working on the Using a Map to Count Words exercise...(http://java.sun.com/developer/onlineTraining/collections/magercises/WordCount/index.html)

Having added the Generics stuff where "needed", ( where I learned it should go or by the compiler telling through warning me, hehe error are my friends ) I find myself stuck with the above warning...
According to TreeMap(), I can place a Comparator object in the constructor to get my list "custom" sorted... And that is what I did by following the exercise instruction and verifying it with the solution source code for the Tester class ( Note: WordCount (with Generics) and CaseInsensitiveComparator compiled fine)
Here is the applicable lines of code:
    Comparator comp = new CaseInsensitiveComparator();
    // Put the original map into a sorted map with the new comparator
    Map <String,Integer> sortedMap = new TreeMap <String,Integer>(comp); // warning related to comp
	sortedMap.putAll(map);
The compiled source codes (including Tester with it warning) works fine and the app runs and give the "correct" result... :-)

So the question is, who do I get rid to the warning properly, being that I have yet to figure it out... I am searching through the APIs, the Generics tut and looking up any documentation that I can find related to beta2 language features ( though they seem kind of light in content, but beta docs usually are) to help me figure out the issue, but no luck yet...

Is there a remedy to this issue that I might have over looked ? or a least can I be pointed in the right direction... other than compiling as 1.4 ( then I would not be learning anything )...

Thanks in advance for any advice or help...

- MaxxDmg...

- ' How should I know, I just wrote the thing...'
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2006
Added on Jun 22 2004
11 comments
1,323 views