java.lang.annotation.Annotation
接口(interface)声明 toString
、hashCode
和 equals
方法(非最终版本) Object 类的公共(public)方法)
我认为如果这些方法没有在Annotation接口(interface)中声明,那么什么都没有改变,因为这些方法已经在Object类中定义了。因此,即使它们没有在此接口(interface)中声明,我们也可以使用它们。那么为什么要在这个接口(interface)中声明这些方法呢? 他们的必需品是什么?
最佳答案
对 SO 的快速查找没有产生任何重要的重复问题,因此我将发布我的评论作为答案。如果有重复,我很乐意删除我的答案以支持重复。
java.lang.annotatino.Annotation
有点特别:
The common interface extended by all annotation types. Note that an interface that manually extends this one does not define an annotation type.
注释不是普通对象 hirachy 的一部分。因此,该接口(interface)可以被视为注释的“根对象”1。
<小时/>1 注释并不是真正的对象,因此引号也是如此。除了隐式实现接口(interface) java.lang.annotation.Annotation
的所有注释之外,注释类型中没有继承。
关于java - 为什么在 Annotation 接口(interface)中声明 Object 的非最终公共(public)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49813989/