0
votes

When I try put the const val like this:

const val DRAWABLE_RIGHT : Int = 2

inside a method, I get the error:

Modifier 'const' is not applicable to 'local variable'

And when I move this const val to the top of class like this:

class MyClass @JvmOverloads constructor(context: Context) : ConstraintLayout(context) {
    const val DRAWABLE_RIGHT : Int = 2
    ...
}

the compiler say that it's still incorrect:

Const 'val' are only allowed on top level or in objects

What does it mean top level?

1

1 Answers

0
votes

Top Level means that you should put the variable outside of the class.

It is also possible to put it inside a companion object.