必须将注释(例如@SampleAnnotation
)仅附加到(放置在)类声明之前吗?我们可以在我们想要应用它的方法之前使用@SampleAnnotation
标记吗?
答案 0 :(得分:1)
这取决于注释。这些是注释的可能位置(来自javadoc @Target
:
> ANNOTATION_TYPE Annotation type declaration
> CONSTRUCTOR Constructor declaration
> FIELD Field declaration (includes enum constants)
> LOCAL_VARIABLE Local variable declaration METHOD Method declaration
> PACKAGE Package declaration
> PARAMETER Parameter declaration
> TYPE Class, interface (including annotation type), or enum declaration