So I've run into an issue that works in Java, but ...
# announcements
d
So I've run into an issue that works in Java, but I can't figure out how to make it work in Kotlin. Specifically, I'm trying to create an empty instance of an enum set given a type reference. Context for this is a custom deserializer to map null to empty set. Here's the code that works in java (type is a CollectionType)
Copy code
Class<Enum> enumType = type.getContentType().getRawClass() as Class<Enum>
EnumSet.noneOf(enumType)
However, the kotlin version does not like the types if implemented as followed
Copy code
val enumType = type.contentType.rawClass as Class<Enum<*>>
EnumSet.noneOf(enumType)
The error kotlin displays on the noneOf call is about Enum<*> not being a subtype of Enum<Enum<*>>. Is there any way to make this work? Thanks!
d
Casting to
Class<Nothing>
should work.
d
Nice. I didn't know about that. It works. Thanks
j
Why not just
emptySet<Nothing>()
?
d
That doesn't work because in my case because Jackson throws an argument type mismatch exception since my data class prop is typed as an EnumSet