MVEL - Error: could not access field in ReflectiveAccessorOptimizer
MVEL - Error: could not access field in ReflectiveAccessorOptimizer
我是 MVEL 的新手。按照我遵循的步骤
1) 从 http://mvel.codehaus.org/Downloading+MVEL 下载最新
即下载 mvel2-2.2.0.jar(需要 JDK 1.5+)
2) 创建了一个简单的自定义对象列表
class TestMVEL {
public static void main(String[] p){
String expr0 = "fruits[1]";
String expr1 = "System.out.println(fruits[1]);";
String expr2 = "foreach( f : fruits) { System.out.println(f.getName()); }";
System.out.println(MVEL.eval(expr0, new Basket()));//prints Fruit{name=Banana}
MVEL.eval(expr1, new Basket());// prints Fruit{name=Banana}
MVEL.eval(expr2, new Basket());//error
}
}
class Basket {
List<Fruit> fruits = new ArrayList<Fruit>();
public List<Fruit> getFruits(){
fruits.clear();
fruits.add(new Fruit("Apple"));
fruits.add(new Fruit("Banana"));
fruits.add(new Fruit("Orange"));
return fruits;
}
}
class Fruit {
private String name;
public Fruit(String n){
name = n;
}
public String getName(){
return name;
}
public String toString() {
return "Fruit{" + "name=" + name + '}';
}
}
3) 低于错误
Exception in thread "main" [Error: f.getName(): Class
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer
can not access a member of class test.Fruit with modifiers "public"] [Near :
{... foreach( f : fruits) { System.out.println(f.getName()); } ....}]
class水果需要public.
public class Fruit...
我是 MVEL 的新手。按照我遵循的步骤
1) 从 http://mvel.codehaus.org/Downloading+MVEL 下载最新 即下载 mvel2-2.2.0.jar(需要 JDK 1.5+)
2) 创建了一个简单的自定义对象列表
class TestMVEL {
public static void main(String[] p){
String expr0 = "fruits[1]";
String expr1 = "System.out.println(fruits[1]);";
String expr2 = "foreach( f : fruits) { System.out.println(f.getName()); }";
System.out.println(MVEL.eval(expr0, new Basket()));//prints Fruit{name=Banana}
MVEL.eval(expr1, new Basket());// prints Fruit{name=Banana}
MVEL.eval(expr2, new Basket());//error
}
}
class Basket {
List<Fruit> fruits = new ArrayList<Fruit>();
public List<Fruit> getFruits(){
fruits.clear();
fruits.add(new Fruit("Apple"));
fruits.add(new Fruit("Banana"));
fruits.add(new Fruit("Orange"));
return fruits;
}
}
class Fruit {
private String name;
public Fruit(String n){
name = n;
}
public String getName(){
return name;
}
public String toString() {
return "Fruit{" + "name=" + name + '}';
}
}
3) 低于错误
Exception in thread "main" [Error: f.getName(): Class org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer can not access a member of class test.Fruit with modifiers "public"] [Near : {... foreach( f : fruits) { System.out.println(f.getName()); } ....}]
class水果需要public.
public class Fruit...