Java枚举类默认是否会扩展Java对象类?
我已经定义了自己的枚举,这将扩展Java Enum类。 Java Enum类是否扩展Java对象类?
enum ORDER {
FIRST,
SECOND,
THIRD,
FOURTH
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,在Java中,任何非编号都是对象实例的参考。换句话说
是
true
,除非AREF
是 null 不管AREF
类型是enum
或普通课程。确实,
enum
关键字“定义了类(称为枚举类型)。枚举类主体可以包括方法和其他字段。编译器在创建枚举时会自动添加一些特殊的方法。”因此,枚举类型的引用具有与其他“常规”对象相同的基本属性。
进行呼叫。
因此,您可以以与使用非Enum类的对象相同的方式
Yes, in java any non-null is a reference for an instance of Object. In other words
is
true
unlessaRef
isnull
regardlessaRef
type is anenum
or a regular class.Indeed, the
enum
keyword "defines a class (called an enum type). The enum class body can include methods and other fields. The compiler automatically adds some special methods when it creates an enum." https://docs.oracle.com/javase/tutorial/java/javaOO/enum.htmlThus, references for enum types have the same elementary properties as other "regular" objects.
Thus, you can make calls like:
in the same way as using an object of a non-enum class.
是的。一个简单的单元测试可以证明您的示例类层次结构是顺序 - > java.lang.enum-> java.lang.Object:
这将返回
Yes. A simple unit test can prove that the class hierarchy in your example is ORDER -> java.lang.Enum -> java.lang.Object:
This will return