Came across this @Deprecated()
today. Curious to know @Deprecated
vs @Deprecated()
but both are resolving to the same interface Deprecated
by the compiler.
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()
. See §9.7.2. Marker Annotations of the Java Language Specification :
A marker annotation is a shorthand designed for use with marker annotation types (§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).
Example 9.7.2-1. Marker Annotations
Here is an example using the
Preliminary
marker annotation type from §9.6.1:@Preliminary public class TimeTravel { ... }
As of Java 8 the @Deprecated
annotation had no elements, so it could only ever be a marker annotation. Since Java 9, however, it now has two elements: since
and 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.