How to convert string to operator in java

后端 未结 9 1660
情歌与酒
情歌与酒 2021-01-16 03:12

I want to convert some String to an operator like this:

int value = 1;
int valueToCompare = 3;
String operation = \"<\";

if (value operation         


        
9条回答
  •  生来不讨喜
    2021-01-16 03:52

    Answer

    For completeness¸I would like to add that there already exists a lot of code for this. I know you asked a very specific question, but the general answer would be to look at existing solutions how that is done.

    Example:

    Built-in method for evaluating math expressions in Java

提交回复
热议问题