I have a project that is written with both Java and Kotlin languages and recently I faced next issue.
Let's say we have MyMonth enum:
public enum MyMonth {
JAN("January"),
FEB("February");
private final String name;
MyMonth(final String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Then in Kotlin when we print the name of the month:
fun main() {
val month = MyMonth.JAN
println(month.name)
}
we get:
JAN
which is what is described in the documentation https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-enum/name.html, however actually the name should be January.
Is there a way to get a name in Kotlin that is specified in Java enum?
UPD: My Kotlin version is 1.3.30-release-170
UPD2: IDEA even shows me that name is coming from the getName() method defined in Java:

UPD3: When we explicitly use .getName() it works, however it looks kind of weird
MyMonth.JAN.nameinstead?nameproperty, as seen here, there's a conflict between the Java getter and the Kotlin property. If possible, I recommend changing the name of the Java field and getter to something other thannameandgetName(). Personally, I think it's a bad idea to have a field namednamein a Java enum anyway, considering the existence of thename()method. If you can't change it, what if you callgetName()explicitly in the Kotlin code?