当在 2.9.0-1 中混合到具体类中时,特征中的方法会变成易失性方法,但 2.8.1 中不会
我注意到 2.9.0-1 中的这一重大变化(对我来说与 OGNL 一起使用):
我发现在 2.9 中,特征中声明的方法在混合到类中时会变得易失性:
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 中:
它打印出
isVolatile: false
This 实际上对我来说是一个重大变化,因为 OGNL 拒绝在其表达式中执行 volatile (为什么我不知道)。
所以 - 我的问题是;为什么要做出这样的改变?
I noticed this breaking (for me using it with OGNL) change in 2.9.0-1:
I find that, in 2.9, methods declared in a trait become volatile when mixed in a class:
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()))
This prints out
isVolatile: true
But in 2.8.1:
it prints out
isVolatile: false
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不存在“易失性方法”这样的东西。您看到的是设置了 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.