匿名类是内部类的子集吗? [英] Are anonymous classes a subset of inner class?

查看:83
本文介绍了匿名类是内部类的子集吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来像是一个愚蠢的问题,但是所有匿名类都必须在现有类中定义和实例化;因此,它们必须同时是内部类.

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.

推荐答案

这是真的.您的匿名类不能作为单独的类在其他类之外实现,因为它是匿名的,您甚至无法以任何方式对其进行引用.

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.

其他信息: 来自JLS:匿名类始终是内部类(第8.1.3节);它永远不会是静态的(第8.1.1节,第8.5.1节).

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).

这篇关于匿名类是内部类的子集吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆