You can use Map<Character,Object>
where you can store character and object to calculate in single structure and access later with character only without any if-else
or switch
.
Map<Character,Object> map = new HashMap<>();
map.put('+', plusObject);
map.put('-', minusObject);
map.put('*', multiplyObject);
map.put('/', divideObject);
Now my question is this : How can we determine the type of operator
then call the correct class?
map.get(character)
it will return the object according to the character and null
otherwise.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…