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

 

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

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

你可能感兴趣的:(java)