Most elegant way to apply an operator found as a string in java ?

Posted by LB on Stack Overflow See other posts from Stack Overflow or by LB
Published on 2010-06-02T19:12:53Z Indexed on 2010/06/02 19:24 UTC
Read the original article Hit count: 114

Filed under:

Potentially dumb: Assuming I have a string containing an operator what's the best way to apply this operator ?

What i tend to do is :

if(n.getString(1).equals("<<")) {
  result = tmp1 << tmp2;
}

for each kind of operator I have. Is there a better way ?

© Stack Overflow or respective owner

Related posts about java