java注释重载是否可用?

java注释重载是否可用?,java,annotations,overloading,Java,Annotations,Overloading,我定义了一个注释 @Documented @Target(value = ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface ApiParameter { public String name() default ""; public String type() default ""; public String desc() default ""; } 我可以像上面一样在方法参数声明中使

我定义了一个注释

@Documented
@Target(value = ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiParameter {
public String name() default "";

public String type() default "";

public String desc() default "";
}
我可以像上面一样在方法参数声明中使用这个注释

...
@ApiParameter(desc="for desc") String userName,
@ApiParameter(name="for name", desc="for desc") String address,
@ApiParameter(name="for name",type="for type",desc="for desc") Order order
...
我怎样才能使用上面的方法?我想避免键入字段名

...
@ApiParameter("for desc") String userName,
@ApiParameter("for name", "for desc") String address,
@ApiParameter("for name","for type" "for desc") Order order,
...
Plz help ~

仅允许使用单元素注释[]

@Identifier ( ElementValue )
作为
@标识符(value=ElementValue)
的简写

只有当注释类型具有
元素且所有其他元素(如果有)具有默认值时,才能使用单元素注释

如果必须避免在注释中使用字段名,则可以使用单个
String[]value()
元素创建注释

public @interface ApiParameter {
    public String[] value();
}
然后将其用作

@ApiParameter({"for name", "for desc"}) String param
但是,我认为此解决方案不如当前解决方案清晰,更容易出错,并且在通过注释访问数组时,您还必须检查数组的元素数量是否正确。

仅允许使用单元素注释[]

@Documented
@Target(value = ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiParameter {
public String name() default "";

public String type() default "";

public String desc() default "";
}
@Identifier ( ElementValue )
作为
@标识符(value=ElementValue)
的简写

只有当注释类型具有
元素且所有其他元素(如果有)具有默认值时,才能使用单元素注释

如果必须避免在注释中使用字段名,则可以使用单个
String[]value()
元素创建注释

public @interface ApiParameter {
    public String[] value();
}
然后将其用作

@ApiParameter({"for name", "for desc"}) String param
但是,我认为这个解决方案不如您当前的解决方案清晰,更容易出错,并且在通过注释访问数组时,您还必须检查数组中的元素数量是否正确

@Documented
@Target(value = ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiParameter {
public String name() default "";

public String type() default "";

public String desc() default "";
}