java – 方法签名中的’volatile’?

前端之家收集整理的这篇文章主要介绍了java – 方法签名中的’volatile’?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Why make a method volatile in java?7个
这个很奇怪.我有以下代码: @H_502_3@class A { protected A clone() throws CloneNotSupportedException { return (A) super.clone(); } }

当我通过’showmycode.com’解码它的字节码时,它向我展示了以下代码

@H_502_3@class A { A() { } protected A clone() throws clonenotsupportedexception { return (A)super.clone(); } protected volatile object clone() throws clonenotsupportedexception { return clone(); } }

在第二个’clone’方法中,方法返回类型是volatile的意思是什么? (此代码是通过Eclipse的默认JDK 1.6编译器编译的).

解决方法

字段和方法的修饰符掩码类似但不完全相同.反编译器最有可能在这里使用toString方法

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/reflect/Modifier.java

但它没有做的是处理所有的比特

@H_502_3@// Bits not (yet) exposed in the public API either because they // have different meanings for fields and methods and there is no // way to distinguish between the two in this class,or because // they are not Java programming language keywords

它不能处理的是可以表示编译器生成代码的合成和桥接的位.

如果volatile在这里意味着任何东西,它可能意味着即使它没有做任何事情也不要删除方法.

猜你在找的Java相关文章