java自定义注解类中的方法可以带参数吗?

来源:互联网 发布:花生壳linux 编辑:程序博客网 时间:2024/04/30 21:34

答案:否。

可以 自己写一个 注解类测试一下,如下:

package test;


import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface testAn {
public int alert();
public int test(int a);


}


编译报错如下:

Annotation attributes cannot have parameters

译为:注解属性不能包含参数。








0 1
原创粉丝点击