简体   繁体   English

注释 object 是否扩展了 Z93F725A07423FE1C8896ZF448B33D21 中的 Object class?

[英]Does an annotation object extend the Object class in java?

I know that an annotation object is created implicitly by the JVM.我知道注释 object 是由 JVM 隐式创建的。 Also, I know that all objects in java inherit the superclass Object.另外,我知道 java 中的所有对象都继承了超类 Object。 However, if by reflection you retrieve an annotation object, it doesn't seem to have the methods finalise() and clone() which are defined by the Object class in java. However, if by reflection you retrieve an annotation object, it doesn't seem to have the methods finalise() and clone() which are defined by the Object class in java. Does an annotation object indeed inherit the Object class?注释 object 是否确实继承了 Object class? Is there a reason why an annotation object doesn't define those methods?注释 object 没有定义这些方法是否有原因?

An example code snippet here:这里有一个示例代码片段:

Class<autobot> jane = autobot.class;
about frank = jane.getAnnotation(about.class);
frank.clone();      // This generates an error
frank.finalize();  //  This generates an error

Where " autobot " is an annotated class and " about " is the annotation type.其中“ autobot ”是带注释的 class,“ about ”是注释类型。

It does.确实如此。 clone() and finalize() aren't public. clone()finalize()不是公开的。 This doesn't work either:这也不起作用:

Object o = new Object();
o.clone(); // nope
o.finalize(); // nope

It may work on certain classes.可能适用于某些课程。 For example, this DOES work:例如,这确实有效:

ArrayList<String> o = new ArrayList<String>();
o.clone();

That's simply because class ArrayList itself has overridden the clone() method and made it public .这仅仅是因为class ArrayList本身已经覆盖了clone()方法并将其public You can override a method and make it more public (you can't make em less public).您可以覆盖一个方法并使其更加公开(您不能让 em 不那么公开)。

The type def of an annotation doesn't make anything more public.注释的类型 def 不会使任何内容更加公开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM