Java 注释接口的用途是什么?

Java 注释接口的用途是什么?,java,annotations,Java,Annotations,每个注释类型都隐式继承java.lang.annotation.annotation接口 package java.lang.annotation; public interface Annotation{ boolean equals(Object obj); int hashCode(); String toString(); Class<? extends Annotation> annotationType(); } 那么,谁能给我解释一下吗 注释接口的用途

每个注释类型都隐式继承java.lang.annotation.annotation接口

package java.lang.annotation;
public interface Annotation{
  boolean equals(Object obj);
  int hashCode();
  String toString();
  Class<? extends Annotation> annotationType();
}
那么,谁能给我解释一下吗

注释接口的用途是什么?到底是为了什么 使用了什么

是一个接口。这些方法是您的标准接口
abstract
方法声明

在你的例子中,你指的是什么

@CustomAnnotation(toString="toStringValue")
(使用
toString
)是一种安全的方法。这是两件不同的事情。后者是注释类型的特殊语法<代码>注释不是注释类型,而是接口类型

注释
类型提供的是注释类型的通用超类型。所以你可以

Annotation custom = SomeClass.class.getAnnotation(CustomAnnotation.class);
custom.annotationType();

这些方法(
equals
toString
hashCode
)只需在
注释
界面中重新定义,即可指定它们的行为。它们不是严格要求的,因为如果Java语言不声明它们,则会隐式地声明它们。

中的:“如果在注释类型中声明的任何方法的签名与在类对象或接口Java.lang.annotation.annotation中声明的任何公共或受保护方法的签名等效,则这是一个编译时错误。”因此,也许这就是这个接口的目的(强制执行)注释类型也是一种没有限制的接口,它的限制之一是注释类型之间不允许继承,那么创建超级类型有什么意义呢?注释类型提供的是注释类型的通用超类型,如果这是唯一的目的,为什么注释不是标记接口?我很困惑@AmitBhati注释类型是接口类型,但接口类型不一定是注释类型。它不是一个标记接口,因为Java语言希望包含更多的行为(
annotationType
方法),并为其他3种方法描述更具体的行为。
Annotation custom = SomeClass.class.getAnnotation(CustomAnnotation.class);
custom.annotationType();