I have this enum:
public enum Operation {
ADD {
public double apply(double a, double b) {
return a + b;
}
},
SUBTRACT {
public double apply(double a, double b) {
return a - b;
}
}
} ;
public abstract double apply(double a, double b);
`}`
I want to instantiate this like:
Operation op=new Operation("+");
op.aply(2,3);//now use ADD
Is it possible to write a constructor with string parameter that tells to enum which operation to aply?
Operation.ADD.apply(2, 3);