在AndroidStudio中,我们可以仅使用@IntegerRes
来表示Int
参数必须是资源。
如果我们使用Int
而不是Resource
值,它将动态地抱怨(在编码时,在编译之前)
Expected resource of type integer less... (⌘F1)
Ensures that resource id's passed to APIs are of the right type; for example, calling Resources.getColor(R.string.name) is wrong.
点击进入@IntegerRes
,将看到以下代码。
/**
* Denotes that an integer parameter, field or method return value is expected
* to be an integer resource reference (e.g. {@code android.R.integer.config_shortAnimTime}).
*/
@Documented
@Retention(CLASS)
@Target({METHOD, PARAMETER, FIELD, LOCAL_VARIABLE})
public @interface IntegerRes {
}
我想研究如何动态处理此批注,因此可以进行批注。在哪里可以找到此代码的来源? (我以为所有Android代码都是开源的)
答案 0 :(得分:1)
关于如何实现自定义棉绒检查的文章很多。 Like this one,甚至还有links a repository with further examples。
由于您似乎不愿意实际使用我提供的资源,因此在此检查了“参数注释”,例如,一个@ColorInt
注释的参数是否实际上传递了有效的颜色: