【发布时间】:2020-07-15 15:54:19
【问题描述】:
我有以下方法,其中我使用List<GPathResult> filteredList 返回一个List<ImField> 对象。我在我生成的地方执行filteredList.each 闭包
在运行时类并为其分配静态类型ImField。
static List<ImField> getFields(GPathResult root,String fieldClass, String fieldType){
List<GPathResult> filteredList = root.children().findAll{
XMLSlurperUtil.name(it as GPathResult) == fieldType
} as List<GPathResult>
List<ImField> fields = []
filteredList.each{GPathResult it, int index ->
fields.add(Class.forName(fieldClass).newInstance() as ImField)
fields[index].set(it)
}
fields
}
函数调用如下所示:
ImStageUtil.getFields(root, ImFieldFactory.SOURCE_FIELD, ImParserConstants.SOURCE_FIELD)
ImFieldFactory.SOURCE_FIELD = "com.dto.fields.SourceField"
和ImParserContants.SOURCE_FIELD = "SOURCEFIELD"
错误发生在.each闭包行:
No signature of method: com.extractor.ImStageUtil$_getFields_closure11.doCall() is applicable for argument types: (groovy.util.slurpersupport.NodeChild) values: []
Possible solutions: doCall(groovy.util.slurpersupport.GPathResult, int), findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)
groovy.lang.MissingMethodException: No signature of method: com.extractor.ImStageUtil$_getFields_closure11.doCall() is applicable for argument types: (groovy.util.slurpersupport.NodeChild) values: []
Possible solutions: doCall(groovy.util.slurpersupport.GPathResult, int), findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)
【问题讨论】:
标签: oop groovy reflection closures gpath