当在 2.9.0-1 但不是 2.8.1 中的具体类中混合时,trait 中的方法变成了 volatile 方法 [英] Methods in trait become volatile methods when mixed in concrete classes in 2.9.0-1 but not 2.8.1
问题描述
我注意到 2.9.0-1 中的这一重大变化(对我来说与 OGNL 一起使用):
I noticed this breaking (for me using it with OGNL) change in 2.9.0-1:
我发现,在 2.9 中,在 trait 中声明的方法在混入类中时会变得不稳定:
I find that, in 2.9, methods declared in a trait become volatile when mixed in a class:
2.9.0-1 中的例子
Example in 2.9.0-1
import java.lang.reflect.Modifier
trait SuperTrait {
def getKnoll = "Kanutten"
}
class KlassWithKnoll extends SuperTrait {
def getKnall = "Mars"
}
val qsc = classOf[KlassWithKnoll]
val knollGetter = qsc.getDeclaredMethod("getKnoll")
println("isVolatile: " + Modifier.isVolatile(knollGetter.getModifiers()))
打印出来
isVolatile: true
但是在 2.8.1 中:
But in 2.8.1:
打印出来
isVolatile: false
这对我来说实际上是一个重大变化,因为 OGNL 拒绝在其表达式中执行 volatile(为什么我不知道).
This is actually a breaking change for me as OGNL refuses to execute volatile (why I don't know) in its expressions.
所以 - 我的问题是;为什么要进行此更改?
So - my question is; Why was this change made?
推荐答案
没有可变方法这样的东西.您所看到的是设置了 0x0040 标志,对于字段是 ACC_VOLATILE,对于方法是 ACC_BRIDGE.由于 Modifier.isVolatile 方法采用 Int,因此它无法真正告诉您您所要求的内容没有意义.
There's no such thing as a volatile method. What you are seeing is that the 0x0040 flag is set, which is ACC_VOLATILE for fields, but ACC_BRIDGE for methods. Since the Modifier.isVolatile method takes an Int, it can't really tell you that what you're asking is not meaningful.
这篇关于当在 2.9.0-1 但不是 2.8.1 中的具体类中混合时,trait 中的方法变成了 volatile 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!