java - String 数组的 @StringDef 自定义注解

标签 java android annotations

我有以下代码:

public static final String MY_CONSTANT_A = "A";
public static final String MY_CONSTANT_B = "B";

@StringDef(value={
        MY_CONSTANT_A,
        MY_CONSTANT_B
})
private @interface MyAnnotation{}

public static void someFunc(@MyAnnotation String str){

}

现在,当我尝试在 someFunc 中使用字符串时,我得到了下一个异常的 lint 错误:

enter image description here

现在,当我将函数更改为 String ... str 时,我不再收到此 lint 错误。

public static void someFunc(@MyAnnotation String... str){

}

enter image description here

有什么方法可以做到这一点?

最佳答案

据我所知,Varargs 没有Support annotationStringDef 也没有这样做。 StringDef 仅适用于 String 数据类型,尚未扩展到 Varargs。

文档没有关于支持 Varargs 的内容:http://developer.android.com/reference/android/support/annotation/StringDef.html

关于java - String 数组的 @StringDef 自定义注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33652955/

相关文章:

java - JVM 解释与 JIT 编译。 JVM 不将字节码编译为机器可读吗?

java - 关于注释+类成员顺序的问题

java - 使用 JDBC 的 tomcat 6.0 抛出 ClassNotFoundException com.mysql.jdbc.Connection

java - 如何获取Struts 2标签中复选框的选中值<s :checkbox> into action class

android - Top_toBottomof 在 constraintlayout 中不起作用。如何在Constraint布局中使用Top_toBottomof?

android - 错误 : Could not find method armeabi-v7a() for arguments [arm64-v8a]

java - 用反射覆盖注释?

ios - MKMapView 中的所有 Annotation 对用户不可见

java - 在执行 mysql insert select query 时-我们可以进行条件检查吗?

安卓 3.0 : cannot style Action Bar 's action item buttons