java synthetic_synthetic

/*

有synthetic标记的field和method是class内部使用的,

正常的源代码里不会出现synthetic field。小颖编译工具用的就是jad.

所有反编译工具都不能保证完全正确地反编译class。所以你不能要求太多。

下面我给大家介绍一下 synthetic

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

*/

class parent{

public void foo(){

System.out.println("this is 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 有所了解。

*/

posted on 2007-10-19 11:07 lk 阅读(683) 评论(0)  编辑  收藏 所属分类: j2se

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值