Here's my code.
String name = "expevaluator." + super.left.getClass().getSimpleName() + super.right.getClass().getSimpleName() + "Addition";
try {
Object instance;
instance = Class.forName(name).newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
Logger.getLogger(Addition.class.getName()).log(Level.SEVERE, null, ex);
}
I'm trying to call the evaluate function of the variable "name" class.
Here's the evaluate function.
public Number evaluate(int left, int right) {
return left + right;
}
That's the evaluate method from IntegerIntegerAddition Class
and I have also the IntegerDoubleAddition Class evaluate method
public Number evaluate(int left, double right) {
return left + right;
}
So the variable name could have "IntegerIntegerAddition" or "IntegerDoubleAddition" and I want with both of them call to the Evaluate method with the 2 parameters.