catspeake
对于Java 1.6 +(不确定1.5),您可以使用自己的自定义注释,这里有一个您可以使用的功能模板:package com.mycompany.annotations;import java.lang.annotation.*;/** * * This element has an experimental maturity. Use with caution. * * * NOTE: The developers of this element is not responsible for the issues created, * using it is not suggested for production environment. If you see this annotation do this, do not do that etc * Enjoy responsibly.... */@Documented //this annotation maybe helpful for your custom annotation@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE, ElementType.ANNOTATION_TYPE, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})public @interface Experimental {}这里是 的源代码,所以大家可能都不想使用元素ElementTypeElementType.TYPE_USE, ElementType.TYPE_PARAMETER /* .... * @since 1.5 * @jls 9.6.4.1 @Target * @jls 4.1 The Kinds of Types and Values */public enum ElementType {/** Class, interface (including annotation type), or enum declaration */TYPE,/** Field declaration (includes enum constants) */FIELD,/** Method declaration */METHOD,/** Formal parameter declaration */PARAMETER,/** Constructor declaration */CONSTRUCTOR,/** Local variable declaration */LOCAL_VARIABLE,/** Annotation type declaration */ANNOTATION_TYPE,/** Package declaration */PACKAGE,/** * Type parameter declaration * * @since 1.8 */TYPE_PARAMETER,/** * Use of a type * * @since 1.8 */ TYPE_USE}顺便说一句,这是我从我的IntelliJ中看到的,当我搜索可能实现的库时,可能已经实现了实验有一个用Java 9定义的注释。但请注意,它是在Oracle JDK中,而不是OpenJDK中。在撰写本文时,您需要从官方网站安装jdk-11才能查看/使用它。我不会把它用于这个目的,因为斯蒂芬C.列出的事实。Experimental无论如何,您都不能将其用于方法。因为它的源代码是... package jdk.jfr;/* ... * * @since 9 */@MetadataDefinition@Label("Experimental")@Description("Element is not to be shown to a user by default")@Inherited@Retention(RetentionPolicy.RUNTIME)@Target({ ElementType.FIELD, ElementType.TYPE })public @interface Experimental {}