I have created a Kotlin enum and need to pass it's...
# announcements
g
I have created a Kotlin enum and need to pass it's Java Class equivalent to `org.neo4j.ogm.typeconversion.EnumStringConverter`'s (Java library) constructor. This constructor takes a
Class<? extends Enum>
, which I cannot figure out how to get from my Kotlin enum. I've tried
MyEnum
,
MyEnum.javaClass
and
MyEnum::class
all with/without companion object on MyEnum, all with different compile errors. How do I get MyEnum's
java.lang.Class<? extends java.lang.Enum>
?
a
Have you tried
MyEnum::class.java
?
1
g
now i have, thanks!
k
The reason this happens is that
x.javaClass
means "the class of the instance x", eg.
"hey".javaClass == java.lang.String
. In your code
MyEnum
refers to the companion instance, and that's why you get the wrong class.