Are anonymous classes a subset of inner class?

后端 未结 2 1062
小蘑菇
小蘑菇 2021-01-29 07:45

It might sound like a dumb question, but all anonymous classes must be defined and instantiated within an existing class; therefore, they must be inner classes at the same time.

2条回答
  •  天涯浪人
    2021-01-29 08:22

    This is quite true. Your anonymus class could not be implemented outside of other classes, as a seperate class, because as it is anonymus you would not be even able to refer to it in any way.

    Additional information: From JLS: An anonymous class is always an inner class (§8.1.3); it is never static (§8.1.1, §8.5.1).

提交回复
热议问题