java 复合_java语言中定义的复合类(synthetic)

本文介绍了Java语言规范中关于synthetic构造器的概念,即当编译器为了实现某些功能(如访问私有构造器或方法)而引入的非源代码直接对应的代码块。例如,在创建匿名内部类时,编译器会生成synthetic方法。这些方法在源代码中不可见,但对程序运行至关重要。同时,文章提到了默认构造器和类初始化方法不被视为synthetic的情况。
摘要由CSDN通过智能技术生成

Any constructs introduced by the  compiler that do not have a corresponding construct in the source code must be marked as synthetic ,except for default constructs and the class initialization method.

-----

这是Java语言规范中对synthetic的定义.意思大概是这样滴.

任何被编译器引入的构造器在源代码中没有一个相应的构造器 那么该段代码就必须要被标记为synthetic的(复合的) 除了默认的构造器和类初始化方法.

比如:

class MyOuter { private MyInner inner; void createInner() { // The Compiler has to create a synthetic method // to construct a new MyInner because the constructor // is private. // --> synthetic "constructor" method inner = new MyInner(); // The Compiler has to create a synthetic method // to doSomething on MyInner object because this // method is private. // --> synthetic "constructor" method inner.doSomething(); } private class MyInner { // the inner class holds a syntetic ref_pointer to // the outer "parent" class // --> synthetic field private MyInner() { } private void doSomething() { } } }

由此:有匿名类部类的类可以称作为复合类

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2010-11-23 00:18

浏览 6085

评论

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值