利用bsh.jar 解决负载逻辑运算如:String s="2>3||3>4&&5<4"

http://www.beanshell.org/bsh-core-2.0b4.jar

package test;

import java.util.Date;
import bsh.EvalError;
import bsh.Interpreter;

public class Test {
 public static void main(String[] args) {
  Interpreter interpreter = new Interpreter();
  String s = "2>3||3>4&&5<4";
  try {
   interpreter.set("boolean", interpreter.eval("(" + s +")"));
   System.out.println(interpreter.get("boolean"));
  } catch (EvalError e) {
   e.printStackTrace();
  }
 }
}

你可能感兴趣的:(String)