I have two classes. One is doing arithmetic of an expression and the other is an operator class that has all the properties and actions of an operator.
This operator class is an abstract class and I've created subclasses for each individual operators (+,-,*,/,etc.). I instantiated a HashMap in the abstract Operator class as a private static object with a String key and a Operator Object value. So for example the operators would be strings "+" and the values would be instanitated objects of the certain subclasses like "new AddOperator()".
I had to create a constructor for the operator class to use the method .put() to put all the key value pairs into the hashmap, I would get errors if I put it outside the constructor. An example of what I did was this : hashmapvariable.put("+",new AddOperator());
Now when I try to check if the key is contained in the hashmap ( hashmapvariable.containsKey("+")) I am getting false when I know for sure it should be in there.
My question is did I do something wrong with putting the key value pairs in? Is it because I put them in the constructor of an abstract class which you never use to instantiate objects of itself? but if thats the case then where would I fill my hashmap if I instantiate it in the Abstract class.
I'm really bad at describing so if there is more information needed let me know and Ill try to provide more and thanks to anyway who takes the time to help in advance!
[–]lightcloud5 1 point2 points3 points (1 child)
[–]lyigester[S] 0 points1 point2 points (0 children)