Is there any way to make a string as a condtion in java.
Sample is shown below
class A {
public static void main(String args[]) {
B b = new B(10, 20);
b.setCondition("val1>val2");
}
}
class B {
int val1 = 0;
int val2 = 0;
public B(int v1, int v2) {
val1 = v1;
val2 = v2;
}
public void setCondition(String condition){
//the string should be evaluated as conditon like below.
if(condition) -> if(val1>val2)
}
}
Is this is possibility in java. Thank you.