• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with HashMap object mapping-- type mismatch how to fix?

 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, my HashMap is set to take variables/objects in this class called TPLVariables. A TPLVariable can be of the type TPLString or TPLInt. I instantiated the HashMap like this:



but then I need it to create the right type of variable, so I put in this:



Trying to use this line in the declaration however gets me
Error: method put in interface Map<K,V> cannot be applied to given types;
variables.put(name, stringDeclaration);
required: String, StringSplit.TPLVariables
found: String, StringSplit.TPLString



So what do I do now? I'm trying to see how I can have both types use the same method. Thanks!
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the TPLString class a subclass of TPLVariable, or is it a subclass of TPLVariables?
 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TPLString and TPLInt are subclasses of the TPLVariable class-- oh wait, did I just make a mistake in typing the superclass? TPLVariable is an abstract class though.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't matter if TPLVariable is abstract. It does matter if TPLVariables is another class, of which TPLString is not a subclass.
 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TPLVariables is the class that has my HashMap in it, and TPLVariable is the abstract superclass for TPLString and TPLInt, so it's definitely not a subclass of TPLVariables.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. Then you would want this:

Wouldn't you? After all the values of the Map are going to be TPLVariable objects, not TPLVariables objects.

(It appears that by choosing those two almost-identical names for those classes you have caused yourself some confusion.)
 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhm yeah, thanks for posting the fix, though I came to that conclusion myself already. Note to self-- make sure all names are very different in future. I'm getting another error message now though: This line is in a different class implementing an interface called Directive (different HashMap), but needs to get the variable "name" from TPLVariable... I'm getting a "cannot find symbol" error for "name", and it's also throwing this "non-static variable variables cannot be referenced from a static context".

The class in question:

>
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Noam Ingalls wrote:I'm getting a "cannot find symbol" error for "name", and it's also throwing this "non-static variable variables cannot be referenced from a static context".


This looks like the same thing as in the new thread you started. If so, please indicate it here so that people don't start answering the same question in two different places.


[Fixed Quote]
 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I ask to close the other thread then or close this one? I think closing this one would be better since the original issue is kinda resolved.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Noam Ingalls wrote:Should I ask to close the other thread then or close this one? I think closing this one would be better since the original issue is kinda resolved.


Is this the other thread?
 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:
Noam Ingalls wrote:Should I ask to close the other thread then or close this one? I think closing this one would be better since the original issue is kinda resolved.


Is this the other thread?


No, but come down to it the problem I was having when I asked that is fairly similar to my current issue here-- in fact, ugh, apologies, I think I've been posting too many new threads perhaps-- the problems are related, being all one project.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic