Methods in trait become volatile methods when mixed in concrete classes in 2.9.0-1 but not 2.8.1

梦想与她 提交于 2019-12-07 09:18:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6774232/methods-in-trait-become-volatile-methods-when-mixed-in-concrete-classes-in-2-9-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!