Kotlin Annotation IntDef

前端 未结 6 1995
不知归路
不知归路 2020-12-03 09:53

I have this code sample:

class MeasureTextView: TextView {
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: Attr         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 10:08

    Strange thing, but this question comes in search before the same with right answer

    Copying it here:

    import android.support.annotation.IntDef
    public class Test {
    
        companion object {
    
             @IntDef(SLOW, NORMAL, FAST)
             @Retention(AnnotationRetention.SOURCE)
             annotation class Speed
    
             const val SLOW = 0
             const val NORMAL = 1
             const val FAST = 2
        }
    
        @Speed
        private var speed: Int=SLOW
    
        public fun setSpeed(@Speed speed: Int) {
            this.speed = speed
        }
    }
    

提交回复
热议问题