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

日期: 2025-03-25 12:08:32 |浏览: 2|编号: 84841

友情提醒:信息内容由网友发布,本站并不对内容真实性负责,请自鉴内容真实性。

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

Any by the that do not have a in the code must be as , for and the class .

-----

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

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

比如:

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() { } } } 

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

提醒:请联系我时一定说明是从旅游网上看到的!