为简单起见,假设我有类似这样的代码:
def testMethod(String txt) {
return txt;
}
public String evaluate(String expression) {
//String result = "${testMethod('asdasdasd')}";
String result = "${expression}";
return result;
}
我需要执行传递给方法“evaluate”的表达式值。
在打电话的情况下
// everything works perfectly well,
String result = "${testMethod('samplestring')}";
在打电话的情况下
// (when expression = testMethod) - everything works perfectly well,
String result = "${expression}"("samplestring");
在打电话的情况下
// (when expression = testMethod('samplestring')) - it's not working.
// I see testMethod('samplestring') as the result, but I need it to be evaluated.
String result = "${expression}"
我怎样才能做到这一点?谢谢。