【发布时间】:2019-07-22 12:30:32
【问题描述】:
假设我有以下课程:
@Slf4j
class MySuperclass {
public void testMethod() {
def test = [1, 2, 3]
test.each {it ->
log.info("gab" + it)
def test2 = [4,5,6]
test2.each {
log.info("" + it)
}
}
}
}
然后:
class MySubclass extends MySuperclass {
public void process() {
testMethod()
}
}
当我调用mySubclass.process() 时,我得到一个错误:
No such property log for class: com.ingenuity.app.kang.batch.MySubclass
该错误仅针对 test2 闭包内的行引发。如果我声明一个公共日志字段,它工作正常。如果我在子类中添加@Slf4j 注释,它也可以正常工作。
我不明白这里发生了什么。这是一个时髦的错误吗? 我发现这个问题可能是相关的,但它不是相同的行为: Groovy closure not work with static final field from super class
【问题讨论】:
-
我猜这个链接projectlombok.org/features/log可能会给你一些解决问题的想法。