这在Groovy中是合法的吗?
class RequestContext {
def static requestContext
def static setRequestContext(rc) {
requestContext = rc
}
}鉴于上述情况,我预计以下代码会在使用groovy-eclipse编译器编译时失败:
RequestContext.setRequestContext()
然而,这已经过去了,我正在尝试让它在mvn compile时间失败。
发布于 2020-03-27 06:36:02
它不会在编译时失败,因为您可以在运行时通过元类动态添加该方法,例如:
class Test {
}
Test.metaClass.static.woo = { -> println "yay" }
Test.woo() // prints 'yay'要在编译时失败,需要用@CompileStatic或@TypeChecked注释调用类
https://stackoverflow.com/questions/60877158
复制相似问题