问题描述
限时送ChatGPT账号..我有这个代码示例:
class MeasureTextView: TextView {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
companion object{
val UNIT_NONE = -1
val UNIT_KG = 1
val UNIT_LB = 0
}
fun setMeasureText(number: Float, unitType: Int){
val suffix = when(unitType){
UNIT_NONE -> {
EMPTY_STRING
}
UNIT_KG -> {
KG_SUFIX
}
UNIT_LB -> {
LB_SUFIX
}
else -> throw IllegalArgumentException("Wrong unitType passed to formatter: MeasureTextView.setMeasureText")
}
// set the final text
text = "$number $suffix"
}
}
我希望能够在编译时将自动完成功能与 IntDef 注释结合使用,因此当我调用 setMeasureText(...)
时,静态变量显示为该方法参数的选项.
I want to be able to use, at compile time, the auto complete feature in conjunction with IntDef annotation, so when i invoke setMeasureText(...)
,
the static variables are shown as options to the argument of this method.
我已经搜索过这个,但我找不到 Kotlin 是否支持这种 java 样式的注释(例如 intdef).所以我试过了,并为此做了一个注释,但它不会在自动完成中显示.
I have searched about this, and i couldn't find if Kotlin supported this java-style annotations (intdef for example). So i have tried it, and made an annotation for this, but it won't show in autocompletion.
我的问题:- Kotlin(最新版本)是否支持Java注解IntDef
My question: - Is Java annotation IntDef supported in Kotlin (latest version)
如果是,我如何在 Android Studio IDE 中打开(如果它有效,我无法让编译器建议它).
If it is, how can i turn in ON in the Android Studio IDE (if it works, i can't get the compiler to suggest it).
如果不是,是否有任何 Kotlin 方式进行编译时检查
If it is not, is there any Kotlin-way of make this compile time checks
推荐答案
从 Kotlin 1.0.3 开始,不支持 @IntDef
注释,但计划在以后的版本中支持.
As of Kotlin 1.0.3, the @IntDef
annotation is not supported, but support is planned for later versions.
Kotlin 进行这些编译时检查的方法是使用 enum 类
而不是一系列 Int
常量.
The Kotlin way of making these compile time checks is to use an enum class
instead of a series of Int
constants.
这篇关于Kotlin 注释 IntDef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论