in my application I want to create a very basic enum class, like this one:
enum class Week (val printableName: String) {
MONDAY("Monday"),
TUESDAY("Tuesday"),
WEDNESDAY("Wednesday"),
THURSDAY("Thursday"),
FRIDAY("Friday"),
SATURDAY("Saturday"),
SUNDAY("Sunday")
}
and I want to retrieve the printablenName from an activity in java, not in kotlin.
I do it as follows:
String day = Week.FRIDAY.getPrintableName();
However, I always get the same error:
error: package Week does not exist
String color = Week.FRIDAY.getPrintableName();
What am I forgetting?
CodePudding user response:
Write the full path from root
of you project into the day or color field
String day = pathFromRoot.Week.FRIDAY.getPrintableName();
CodePudding user response:
This actually not how you retrieve a getter function in Java. Please refer this: https://kotlinlang.org/docs/java-to-kotlin-interop.html#package-level-functions
Basically you have to add your package name like packageName.Week.getPrintableName()