gpt4 book ai didi

expression - MVEL-错误 : could not access field in ReflectiveAccessorOptimizer

转载 作者:行者123 更新时间:2023-12-05 06:44:37 28 4
gpt4 key购买 nike

我是 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()); } ....}]

最佳答案

Fruit 类需要公开。

public class Fruit...

关于expression - MVEL-错误 : could not access field in ReflectiveAccessorOptimizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28387554/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com