Java中内部类的用途是什么?嵌套类和内部类是一样的吗?

问题描述:


可能重复:

Java内部类和静态嵌套类

Java中内部类的用途是什么?嵌套类和内部类是否相同?

What are the uses of inner classes in Java? Are nested classes and inner classes the same?

不,它们不一样:内部类是非 static 。

No, they're not the same: an inner class is non-static.


JLS 8.1.3内部类和附件实例



内部类是一个嵌套类,未显式或隐式声明为静态。

JLS 8.1.3 Inner Classes and Enclosing Instances

An inner class is a nested class that is not explicitly or implicitly declared static.

另请参阅Joe Darcy的下图:

Consult also the following diagram from Joe Darcy:




Joseph D. Darcy's Oracle Weblog - Nested, Inner, Member, and Top-Level Classes






相关问题