如何自定义java注解

1.创建一个自定义注解:与创建接口类似,但自定义注解需要使用@interface

2.添加元注解信息,比如@Target,@Retetion,@Document,@Inherited等

3.创建注解方法,但注解方法不能带有参数

4.注解方法返回值为基本类型,String,Enums,Annotation 或其数组

5.注解可以有默认值

@Target(FIELD)
@Retention(RUNTIME)
@Documented
public @interface CarName{

String value() default "";
}

猜你喜欢

转载自blog.csdn.net/weixin_58419099/article/details/131237673