Given this bit of Kotlin:
object OldTownRoad {
const val COWBOY_HATS = "from Gucci"
const val WRANGLER = "on my booty"
}
and this Java class:
public class Scrap {
@Named(OldTownRoad.COWBOY_HATS)
public void lilNasXrefs() {
System.out.println(OldTownRoad.COWBOY_HATS);
System.out.println(OldTownRoad.WRANGLER);
}
}
The compiler is happy with the println()
calls. It complains about the use of COWBOY_HATS
in the @Named
annotation, saying "Attribute value must be constant", as seen in this Android Studio 3.5.3 screenshot:
I tried @JvmStatic
and @JvmField
on those const val
declarations, but the compiler complains that neither are valid for const
properties.
I get the same results from a companion object
:
class OldTownRoad {
companion object {
const val COWBOY_HATS = "from Gucci"
const val WRANGLER = "on my booty"
}
}
Is there some other Kotlin constant syntax that works when referenced from a Java annotation?