aspose file tools*
The moose likes Beginning Java and the fly likes TreeMap compile error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "TreeMap compile error" Watch "TreeMap compile error" New topic
Author

TreeMap compile error

Michael Salvini
Greenhorn

Joined: May 25, 2010
Posts: 20
Good Evening All,

I wasn't sure if I should post this in Java in General or Beginning Java. I went with Beginning Java because I am just beginning, but I do apologize if this should be in another forum.

I have a class (LoginFrame) that calls a static method from another class (Users). The static method in class Users is here:



As you can see I am returning the TreeMap users which I have initialized as TreeMap<String,String>.

In my LoginFrame class, I store the results of the above method. The line that declares this and calls the method is here:



When I compiled it, I got the following notes.

Note: LoginFrame.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: LoginFrame.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.


I then recompiled with "-Xlint:unchecked" specified at the command line and got the following warnings:

LoginFrame.java:146: warning: [unchecked] unchecked conversion
found : java.util.TreeMap
required: java.util.TreeMap<java.lang.String,java.lang.String>
TreeMap<String,String> users = Users.getUsernamesAndPasswords();
^
1 warning
LoginFrame.java:146: warning: [unchecked] unchecked conversion
found : java.util.TreeMap
required: java.util.TreeMap<java.lang.String,java.lang.String>
TreeMap<String,String> users = Users.getUsernamesAndPasswords();
^
1 warning


While I realize these are not show stoppers, and everything works as expected, I am trying to understand why this is happening. I realize that in the Users class, the TreeMap is declared with a type of <String,String>, so I thought I did the right thing by declaring if the same way in my LoginFrame class. Is this not the proper way? Any ideas as to why this is happening?

Thanks,
Mike


Learning Java & Studying for the SCJA
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You should declare your static method the following way :


[My Blog]
All roads lead to JavaRanch
Michael Salvini
Greenhorn

Joined: May 25, 2010
Posts: 20
Thank you so much. You know, I kept going back over the code multiple times trying to figure out if I had the TreeMap initialized somewhere else and never found it, but I never thought about the method declaration.

Thanks for clearing that up for me.

Thanks,
Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TreeMap compile error