This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TreeMap compile error

 
Michael Salvini
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should declare your static method the following way :
 
Michael Salvini
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic