有synthetic标记的field和method是class内部使用的,正常的源代码里不会出现synthetic field。小颖编译工具用的就是jad.所有反编译工具都不能保证完全正确地反编译class。所以你不能要求太多。  下面我给大家介绍一下synthetic  下面的例子是最常见的synthetic field  Java代码 class parent {        public void foo() {        }           class inner {            inner() {          foo();        }        }    }   非static的inner class里面都会有一个this$0的字段保存它的父对象。编译后的inner class 就像下面这样:  Java代码 class parent$inner    {    synthetic parent this$0;    parent$inner(parent this$0)    {    this.this$0 = this$0;    this$0.foo();    }    }   所有父对象的非私有成员都通过 this$0来访问。  还有许多用到synthetic的地方。比如使用了assert 关键字的class会有一个  synthetic static boolean $assertionsDisabled 字段  使用了assert的地方  assert condition;  在class里被编译成  Java代码 if(!$assertionsDisabled && !condition)    {    throw new AssertionError();    }   还有,在jvm里,所有class的私有成员都不允许在其他类里访问,包括它的inner class。在java语言里inner class是可以访问父类的私有成员的。在class里是用如下的方法实现的:  Java代码 class parent    {      private int value = 0;      synthetic static int access$000(parent obj)      {        return value;      }    }   在inner class里通过access$000来访问value字段。  synthetic的概念  According to the JVM Spec: "A class member that does not appear in the source code must be marked using a Synthetic attribute." Also, "The Synthetic attribute was introduced in JDK release 1.1 to support nested classes and interfaces."   I know that nested classes are sometimes implemented using synthetic fields and synthetic contructors, e.g. an inner class may use a synthetic field to save a reference to its outer class instance, and it may generate a synthetic contructor to set that field correctly. I'm not sure if it Java still uses synthetic constructors or methods for this, but I'm pretty sure I did see them used in the past. I don't know why they might need synthetic classes here. On the other hand, something like RMI or java.lang.reflect.Proxy should probably create synthetic classes, since those classes don't actually appear in source code. I just ran a test where Proxy did not create a synthetic instance, but I believe that's probably a bug.  Hmm, we discussed this some time ago back here. It seems like Sun is just ignoring this synthetic attribute, for classes at least, and we should too.  注意上文的第一处黑体部分,一个类的复合属性表示他支持嵌套的类或者接口  注意上文的第二处黑体部分,说明符合这个概念就是OO思想中的类的复合,也就是只要含有其它类的引用即为复合。

java的synthetic_java synthetic关键字相关推荐

  1. java synthetic_Java synthetic 关键字原理解读

    看Java的反射时,看到有个synthetic ,还有一个方法isSynthetic() 很好奇,就了解了一下: 1.定义 Any constructs introduced by a Java co ...

  2. java synthetic_Java 中冷门的 synthetic 关键字原理解读

    看JAVA的反射时,看到有个synthetic ,还有一个方法isSynthetic() 很好奇,就了解了一下: 1.定义 Any constructs introduced by a Java co ...

  3. java synthetic_浅谈Java编程中的synthetic关键字

    导读 正文 java synthetic关键字.有synthetic标记的field和method是class内部使用的,正常的源代码里不会出现synthetic field.小颖编译工具用的就是ja ...

  4. java的synthetic_Java中的synthetic

    有synthetic标记的field和method是class内部使用的,正常的源代码里不会出现synthetic field.小颖编译工具用的就是jad.所有反编译工具都不能保证完全正确地反编译cl ...

  5. 在Java中使用final关键字可以提高性能吗?

    本文翻译自:Does use of final keyword in Java improve the performance? In Java we see lots of places where ...

  6. Java中的synthetic详解

    https://blog.csdn.net/moakun/article/details/80577702 synthetic介绍 有synthetic标记的field和method是class内部使 ...

  7. java中的synthetic

    有synthetic标记的field和method是class内部使用的,正常的源代码里不会出现synthetic field.小颖编译工具用的就是jad.所有反编译工具都不能保证完全正确地反编译cl ...

  8. synthetic关键字和NBAC机制

    1.synthetic关键字 根据Java语言规范,所有存在于字节码文件中,但是不存在于源代码文件中的构造,都应该被synthetic关键字标注 这里的构造,原文是Constructs,实际上指的是字 ...

  9. 面试季,Java中的static关键字解析

    点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面 ...

最新文章

  1. leetcode--对称二叉树--python
  2. 2015年微软亚洲研究院的惊艳项目,人工智能抢眼
  3. matlab上机实验报告,MATLAB上机实验
  4. mesh和wifi中继的区别_什么是MESH WIFI?通俗易懂告诉你为什么需要它
  5. boost::multiprecision模块mpfr相关的测试程序
  6. CSS Sprites原理
  7. 工信部副部长怀进鹏:信息产业呈现四大发展特点
  8. Java虚拟机(十一)——执行引擎
  9. 关联 VMware 产品的内部版本号和版本 (1014508)
  10. listview复用机制研究
  11. HALCON 21.11:深度学习笔记---异常检测(9)
  12. 添加谷歌账户显示与服务器,解决添加google同步帐户出错竟然可以这般简单!
  13. 九宫格游戏(java实现)
  14. 通过QQ 2012 客户端协议获取clientkey的0x91数据包分析
  15. iOS开发直播app-美颜滤镜GPUImageBeautifyFilter
  16. 安卓基于JCVideoPlayer 播放视频(本地网络),基于java计数器实现视频轮播
  17. 那些著名的黑客事件 六
  18. 为什么说信息是负熵?
  19. 黑客逆向破解基础-3:如何识别程序加的什么壳
  20. NVME-MI 学习记录_1 框架

热门文章

  1. C++using声明和using指示
  2. Google Drive共享云端硬盘转存
  3. C语言|04博客作业
  4. 【C操作符详解】之 移位操作符
  5. c语言将数组初始化为1_C语言的数组初始化
  6. win11系统任务栏居中以及透明美化
  7. 写一个rpg maker mv 脚本,功能是让玩家在游戏开始时候可以自己捏脸
  8. android 文本渐变显示
  9. adb之连接夜神模拟器
  10. 翻译翻译什么是拓扑优化算法