1
我有一個似乎做工精細一些Java代碼:invokeMethod中不帶任何參數
/**
* Helper method
* 1. Specify args as Object[] for convenience
* 2. No error if method not implemented
* (GOAL: Groovy scripts as simple as possible)
*
* @param name
* @param args
* @return
*/
Object invokeGroovyScriptMethod(String name, Object[] args) {
Object result = null;
try {
result = groovyObject.invokeMethod(name, args);
} catch (exception) { // THIS HAS BEEN GROVIED...
if (exception instanceof MissingMethodException) {
if (log.isDebugEnabled()) {
log.debug("invokeGroovyScriptMethod: ", exception);
}
} else {
rethrow exception;
}
}
return result;
}
Object invokeGroovyScriptMethod(String name) {
return invokeGroovyScriptMethod(name, [ null ] as Object[]);
}
Object invokeGroovyScriptMethod(String name, Object arg0) {
return invokeGroovyScriptMethod(name, [ arg0 ] as Object[]);
}
Object invokeGroovyScriptMethod(String name, Object arg0, Object arg1) {
return invokeGroovyScriptMethod(name, [ arg0, arg1 ] as Object[]);
}
,但我有方法的問題:
Object invokeGroovyScriptMethod(String name) {
return invokeGroovyScriptMethod(name, [ null ] as Object[]);
}
groovy.lang.MissingMethodException: No signature of method: MyClass.getDescription() is applicable for argument types: (null) values: [null]
Possible solutions: getDescription(), setDescription(java.lang.Object)
任何提示?
謝謝 米莎
哇,這是真棒。我知道我的代碼有什麼問題btw Object invokeGroovyScriptMethod(String name){ return invokeGroovyScriptMethod(name,[null] as Object []); } 應該是 對象invokeGroovyScriptMethod(字符串名稱){ 返回invokeGroovyScriptMethod(姓名,[]爲Object []); } 米莎 – 2010-08-17 16:24:22
換句話說[空]爲Object []應該是[]爲Object [] – 2010-08-17 16:24:46
僅供參考,如果它的好,我張貼您的代碼段在這裏 http://groovy.329449.n5.nabble.com /invokeMethod-from-Groovy-with-no-parameters-td2637455.html#a2637455 – 2010-08-17 16:29:54