我正在尝试使用Groovy(2.1.6)为Fest创建一个闭包匹配器:
def matcherLabel = [ isMatching: { JLabel label -> /* do something */ } ] as GenericTypeMatcher<JLabel>
GenericTypeMatcher是一个抽象类,只有一个方法可以实现(isMatching(T t))
但是我收到了这个错误:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Error casting map to org.fest.swing.core.GenericTypeMatcher, Reason: null
at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:7562)
我想做的可能吗?
答案 0 :(得分:9)
您的问题是GenericTypeMatcher
类没有默认的零参数构造函数。将地图转换为ComponentMatcher
等界面。如果你不能使用接口,另一个选择是子类GenericTypeMatcher
并提供一个零参数构造函数。