Why make a method volatile in java?

后端 未结 7 1198
逝去的感伤
逝去的感伤 2020-12-15 06:23

Why would a method be made volatile? How does making a method volatile change the method\'s behavior?

Edit: I did a toString() on a Method object r

7条回答
  •  粉色の甜心
    2020-12-15 06:33

    It seems that "volatile" methods are produced under the hood by the Java compiler, as "glue methods" for generic methods. Generics will produce under the hood methods which will accept only Object as parameters, and cast them to the specific generic type, while these methods are invisible to the developer. There is a safer way to determine these methods though, by using the method.isBridge()

提交回复
热议问题