@ StringRes,@ DrawableRes,@ LayoutRes等使用Kotlin参数的android批注lint检查 [英] @StringRes, @DrawableRes, @LayoutRes and so on android annotations lint check with kotlin parameters
问题描述
假设您具有带有默认参数的此类数据类
assuming you have such data class with default parameters
data class Info(
@DrawableRes
val iconRes: Int = 0,
@StringRes
val stringRes: Int = 0,
@LayoutRes
val layoutRes: Int = 0)
因此您可以像这样创建此数据类
so you can create this data-class like
val data = Info(
iconRes = R.drawable.icon,
stringRes = R.string.text,
layoutRes = R.layout.layout)
在这种情况下,没有任何棉绒错误
in this case there isn't any lint error
但是当我尝试使用默认参数时,会出现棉绒错误:
But when i try to use default parameters a lint error is occured:
val data = Info(
//here is expected resource of type drawable error
stringRes = R.string.text
layoutRes = R.layout.layout)
似乎它使用参数中的位置,而不是确切的类型&姓名.
Seems that it uses position in parameters, not the exact type & name.
我尝试使用像@param:DrawableRes
这样的显式注释,但结果相同.
I've tried to use explicit annotation like @param:DrawableRes
, but with the same result.
我能以某种方式解决这个问题吗?我使用最新的Android Studio 3.0.
Can i somehow solve this problem? I use latest Android Studio 3.0.
推荐答案
这是Android Studio中的一个问题,已在3.1中修复.在3.1-beta4上检查过
It was an issue in Android Studio and was fixed in 3.1. Checked on 3.1-beta4
这篇关于@ StringRes,@ DrawableRes,@ LayoutRes等使用Kotlin参数的android批注lint检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!