How to convert char to operator?

Hi! the question is simple, but not for me:
have:
int a = 1;
int b = 1;
char c = '+';

how to make to work the System.out.print(a + c + b) is true from the point of view of mathematics (1 + 1 = 2)
and can I assign a variable "a b c" how 1 + 1 = 2?????
I hope you understand me....
March 19th 20 at 08:44
1 answer
March 19th 20 at 08:46
Alas, it is so easy in Java to do operator overloading in Java is missing. You need to write a parser and an interpreter.
But! The easiest option is to use scripts or classes in groovy to Java with very good friends. The interpreter and the parser is already written for you. Download groovy, connect jar to your project, and will Westie.
import groovy.util.Eval
....
assert Eval.me('33*3') == 99
assert Eval.me('"foo".toUpperCase()') == 'FOO'

groovy-lang.org/integrating.html

Find more questions by tags Java