https://kotlinlang.org logo
r

ralf

01/12/2017, 7:07 PM
What’s the best way to define a constant in Kotlin with good Java interoperability? Right now I’ve defined the constant like this:
Copy code
// MyClass.kt
@JvmField
val DEFAULT_FILTER: FilterObject = FilterObject.create()

class MyClass {…}
Problem is in Java I would have to use
MyClassKt.DEFAULT_FILTER
. I’d like to get rid of the
Kt
suffix. The
const
keyword only works for primitives and Strings. A companion object doesn’t work either, then it would look like this
MyClass.Companion.getDEFAULT_FILTER()
. What’s a better way?