是否可以在带注释的类型上定义Kotlin扩展函数?
@ColorInt
fun @ColorInt Int.darken(): Int {
return ColorUtils.blendARGB(this, Color.BLACK, 0.2f)
}
Run Code Online (Sandbox Code Playgroud)
替代形式:
@ColorInt
fun (@ColorInt Int).darken(): Int {
return ColorUtils.blendARGB(this, Color.BLACK, 0.2f)
}
Run Code Online (Sandbox Code Playgroud)
这将对应于以下静态功能:
@ColorInt
fun darken(@ColorInt color: Int): Int {
return ColorUtils.blendARGB(color, Color.BLACK, 0.2f)
}
Run Code Online (Sandbox Code Playgroud)
我不认为这可能还在使用Kotlin,但是可以在以后的Kotlin版本中添加该功能吗?
在一个侧面说明:同样的问题也适用于@IntDef,@StringDef,@[resource type]Res以及.