我正在尝试搜索有关在数组的Android支持库中使用最近引入的注释的任何示例或任何文档。特别是,我想用@StringRes
注释整数数组,如@DrawableRes
,@ColorRes
,Android Studio 1.3
Build #AI-141.2117773, built on July 28, 2015
JRE: 1.6.0_65-b14-466.1-11M4716 x86_64
JVM: Java HotSpot(TM) 64-Bit Server VM by Apple Inc.
等。
我尝试在Android Studio 1.3中使用这些注释,版本细节:
compile 'com.android.support:support-annotations:22.2.0'
支持图书馆声明:public void test(@NonNull Context context) {
method(context, new int[]{1}); // no warn/error here
}
public void method(@NonNull Context context, @DrawableRes int[] ids) {
context.getString(ids[0]); // no warn/error here
}
示例源代码:
public void test(@NonNull Context context) {
method(context, 1, 2, 3); // there is warn only for 2nd argument, saying it must be Drawable type. But no warns to 3rd and 4th params.
}
public void method(@NonNull Context context, @DrawableRes int... ids) {
context.getString(ids[0]); // no warn/error here
}
不幸的是,这段代码没有产生任何错误,没有警告,可能是因为当前版本的资源类型注释并不是设计用于与数组一起使用,但我不确定。
我的问题 - 有没有办法为int数组使用资源类型注释?
更新:
我已经用varargs添加了这个案例,它们看起来也像是破了,但是有点不同:
{{1}}