Bug? Cannot use Kotlin Enum from Groovy

Hi,

I have a problem testing a Kotlin enum class from a Groovy test based on Spock Framework: As it seems the enum values from a data pipe (here: data table) are perceived as classes.

I was able to drill down the problem with the attached files. The ZIP contains:

  • KAngleUnit - the Kotlin Enum AngleUnit with property symbol and method convert
  • JAngleUnit - the same Enum as Java Version
  • JUseAngleUnit - an executable class which accesses both the Kotlin and the Java enum
  • GUseAngleUnit - an executable groovy class which accesses both the Kotlin and the Java enum

JUseAngleUnit runs without errors. GUseAngleUnit fails with:

Java: DEGREE <class JAngleUnit$1>
Kotlin: class KAngleUnit$DEGREE <class java.lang.Class>
0.0
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method:
 static KAngleUnit$DEGREE.convert() is applicable for argument types:
 (java.lang.Double, java.lang.Class) values: [0.0, class KAngleUnit$RADIANT]

The first two lines output the enum value and the result of getClass(). As you can see the Java Enum Value has an anonymous class whereas the Kotlin Enum Value is perceived as Class.

Is this an issue? (I think: yes) And if: Is this is a known issue and does a workaround exist?

kotlin-enum-poc.zip (1,7 KB)

1 Like

Hi @michaelis.mark

I just run into the same problem today.
Do you have any update on this?

Thanks for your feedback & best regards,
Peti

Here is a possible solution : Testing Kotlin with Spock Part 2 – Enum with instance method – Team Blog

1 Like

A further 3 years on from the last comment, and I’ve stumbled into the same issue. The ‘possible solution’ reference above from May 19, is an explanation, but not a practical solution for using Enums defined in Kotlin from Groovy code in general. Is there any better solution?

I believe this problem should be reported primarily to the Groovy issue tracker, however we could take a look what is different except enum entry class names in Kotlin enum code generation approach.

1 Like