Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

TreeMap compile error

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic