groovy的错误
发布时间:2020-12-14 16:53:21 所属栏目:大数据 来源:网络整理
导读:1.Cannot cast object 'org.codehaus.groovy.runtime.MethodClosure@92d6d2' with class 'org.codehaus.groovy.runtime.MethodClosure' to class 'Closure' class MethodClosureSample {int limitpublic MethodClosureSample(int limit) {this.limit = limit
1.Cannot cast object 'org.codehaus.groovy.runtime.MethodClosure@92d6d2' with class 'org.codehaus.groovy.runtime.MethodClosure' to class 'Closure' class MethodClosureSample { int limit public MethodClosureSample(int limit) { this.limit = limit } boolean validate(String value){ return value.length() <= limit } static main(args) { MethodClosureSample first = new MethodClosureSample(6) MethodClosureSample second = new MethodClosureSample(5) Closure firstClosure = first.&validate def words = ['long string','medium','short','tiny'] assert 'medium' == words.find(firstClosure) assert 'short' == words.find(second.&validate) } } 如上代码改成如下的形式: class MethodClosureSample { int limit public MethodClosureSample(int limit) { this.limit = limit } boolean validate(String value){ return value.length() <= limit } static main(args) { MethodClosureSample first = new MethodClosureSample(6) MethodClosureSample second = new MethodClosureSample(5) org.codehaus.groovy.runtime.MethodClosure firstClosure = first.&validate def words = ['long string','tiny'] assert 'medium' == words.find(firstClosure) assert 'short' == words.find(second.&validate) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |