IntDef problem


#1

Hi all,

I’m having an odd problem with IntDef, any parameter I pass to the function after the IntDef parameter is ignored.

code samples:
The annotation decleration (CalcTypes .kt)

class CalcTypes {
    @IntDef(CalcTypes.COLD, CalcTypes.HEAT, CalcTypes.LIQUIDS, CalcTypes.CALORIES)
    @Retention(AnnotationRetention.SOURCE)
    annotation class CalcType

    companion object {
        const val HEAT = 0L
        const val COLD = 1L
        const val LIQUIDS = 2L
        const val CALORIES = 3L
    }
}

CalcActivity.kt

companion object {
        private const val CalcArg = "CALC"
        private const val TitleArg = "TITLE"

        fun createIntent(context: Context, title: String, @CalcTypes.CalcType calc: Long, test: Int): Intent {
            val intent = Intent(context, CalcActivity::class.java)

            intent.extras.putLong(CalcArg, calc)
            intent.extras.putString(TitleArg, title)

            return intent
        }
    }

MainActivity.kt

startActivity(CalcActivity.createIntent(this, "asdasd" , CalcTypes.HEAT, 52))

The parameter test in the CalcActivity is ignored and I get the message parameter 'test' is never used, although I’m passing it, my main problem is when I need to use 2 IntDef parameters.

Does anyone experienced it, and know how to deal with it, is it bug in kotlin ?


#2

You get this warning because the parameter is not used inside the function createIntent