1

Kotlin can't access a field in a java enum because it is called name, which collides with the name variable in Kotlin's definition of Enum, as seen in this question: Conflicting 'name' declaration in enum

The solution to that question was to edit the enum, but I can't edit this Java enum.

How do I resolve the ambiguity for Kotlin so that I can access the name field?

Roland
  • 22,259
  • 4
  • 57
  • 84
lbenedetto
  • 2,022
  • 1
  • 21
  • 39
  • @yole the linked duplicate is not really related to this question... (except for the error message)... the linked duplicate declares a new enum and isn't able to declare an entry with name `name`. In this question however the `enum` is an existing Java enum with a `name`-field... (even though one can definitely argue why anyone wants such a field in an enum :-/) – Roland Jan 14 '19 at 14:28
  • If you are using a library with an enum in it, then its not up to you. Or maybe you have an enum of Countries named after their ISO codes, with the name field being the name of the country, that is depended upon in too many places to refactor. – lbenedetto Jan 14 '19 at 14:35
  • ok... I rather argue about an accessible field in an enum... usually in the Java-world fields are not exposed directly, but rather hidden behind accessor methods... but again: you have that problem... it seems valid to me and not directly related to the linked question. – Roland Jan 14 '19 at 15:45

0 Answers0