[英]What is the difference between @Deprecated vs @Deprecated()?
Came across this @Deprecated()
today.今天遇到了这个
@Deprecated()
。 Curious to know @Deprecated
vs @Deprecated()
but both are resolving to the same interface Deprecated
by the compiler. @Deprecated
知道@Deprecated
与@Deprecated()
但两者都解析为编译器Deprecated
的相同接口。
Are they both different or are they same?它们是不同的还是相同的? Is there some practice to use one over another?
是否有一些练习可以使用一种方法?
They both mean the same thing.他们俩的意思是一样的。
@Deprecated
is simply shorthand for @Deprecated()
. @Deprecated
只是@Deprecated()
简写。 See §9.7.2.见第9.7.2 节。 Marker Annotations of the Java Language Specification :
Java 语言规范的标记注解:
A marker annotation is a shorthand designed for use with marker annotation types (§9.6.1).
标记注释是设计用于标记注释类型(第 9.6.1 节)的速记。
MarkerAnnotation: @ TypeName
It is shorthand for the normal annotation:
它是普通注释的简写:
@TypeName()
It is legal to use marker annotations for annotation types with elements, so long as all the elements have default values (§9.6.2).
对带有元素的注释类型使用标记注释是合法的,只要所有元素都有默认值(第 9.6.2 节)。
Example 9.7.2-1.
例 9.7.2-1。 Marker Annotations
标记注释
Here is an example using the
Preliminary
marker annotation type from §9.6.1:以下是使用 §9.6.1 中的
Preliminary
标记注释类型的示例:@Preliminary public class TimeTravel { ... }
As of Java 8 the @Deprecated
annotation had no elements, so it could only ever be a marker annotation.从 Java 8 开始,
@Deprecated
注释没有元素,因此它只能是标记注释。 Since Java 9, however, it now has two elements: since
and forRemoval
.但是,从 Java 9 开始,它现在有两个元素:
since
和forRemoval
。 But since those elements have default values the annotation can still be used as a marker annotation.但是由于这些元素具有默认值,因此注释仍然可以用作标记注释。
It's not an interface, it is an annotation .它不是一个接口,它是一个注解。
@Deprecated
and @Deprecated()
are the same @Deprecated
和@Deprecated()
是一样的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.