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

下面我给大家介绍一下synthetic

下面的例子是最常见的synthetic field

 class parent {
public void foo() {
} class inner {
inner() {
foo();
}
}
}

非static的inner class里面都会有一个this$0的字段保存它的父对象。编译后的inner class 就像下面这样:

 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里被编译成

 if (!$assertionsDisabled && !condition)  {
throw new AssertionError();
}

还有,在jvm里,所有class的私有成员都不允许在其他类里访问,包括它的inner class。在java语言里inner class是可以访问父类的私有成员的。在class里是用如下的方法实现的:

 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思想中的类的复合,也就是只要含有其它类的引用即为复合。

最新文章

  1. mysql安装和mysql图形界面安装以及文本文件导入mysql
  2. nodemon配置文件简单整理
  3. java设计模式--简单工厂模式
  4. nrf51822裸机教程-SPI(主)
  5. 从URL中获取搜索关键字
  6. Orchard中文学习视频录制完成
  7. C#-将控件动态添加到选项卡页tablepage
  8. Android AlertDialog 设置setSingleChoiceItems不显示列表的原因【setMessage和setSingleChoiceItems不能同时使用】
  9. C# 多线程详解
  10. poj2932 Coneology (扫描线)
  11. Classification of text documents: using a MLComp dataset
  12. 彻底理解容器类(2)------- AbstractCollection深入了解
  13. 30岁程序员的选择,一线OR二线?
  14. 跟我一起读postgresql源码(八)——Executor(查询执行模块之——可优化语句的执行)
  15. iOS学习——自动定位
  16. 创建线程的一般方式和匿名内部类方式对比——实现runnable接口,重新run方法
  17. 消息队列_MSMQ(2)简单应用
  18. SpringBoot 学习教程(二):示例
  19. Ubuntu 14.04 上安装 Gurobi
  20. ORA-00600: [kck_rls_check must use (11,0,0,0,0) or lower] 故障解决

热门文章

  1. 【mysql】备份篇1:使用系统计划任务+mysqldump 定时备份mysql数据库 不用输入密码自动导出sql文件
  2. javascript 中contentWindow和 frames和iframe之间通信
  3. 机器学习:K-近邻算法(KNN)
  4. java HashMap,LinkedHashMap,TreeMap应用
  5. tomcat 部署 RESTful 服务实例
  6. PLSQL Developer连接远程Oracle方法(非安装client)
  7. Microsoft.VisualStudio.Shell.14.0.dll 文件位置
  8. tomcat在ubuntu中设置开机启动
  9. 文本域光标操作(选、添、删、取)的jQuery扩展
  10. 极客技术专题【011期】:EasyUI初级教程