Sergio76
Sergio76

Reputation: 3986

Error retrieving the value in an enum class

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?

Upvotes: 0

Views: 217

Answers (2)

Lunatic
Lunatic

Reputation: 1906

Write the full path from root of you project into the day or color field

String day = pathFromRoot.Week.FRIDAY.getPrintableName();

Upvotes: 2

yH20
yH20

Reputation: 56

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()

Upvotes: 1

Related Questions