1

I'm trying to access a data class with embedded enum from java

data class MyStatus( val status: Status ) {
   enum class Status{ OK, ERROR }
}

Seems that Status is invisible if I use it from Java. Is there any way to achieve this ?

2
  • 1
    make it public ;) Commented Oct 20, 2017 at 9:03
  • 2
    @VeselinDadidov It is public already since public is the default visibility modifier in Kotlin Commented Oct 20, 2017 at 9:16

1 Answer 1

2

No there's no problem, just do MyStatus s = new MyStatus(MyStatus.Status.ERROR);

Here's what the compiler generates for your Enum:

public static enum Status {
  OK,
  ERROR;
}

It's nested in MyStatus.

Sign up to request clarification or add additional context in comments.

4 Comments

That is what I've tried. But I did it in Eclipse with the Eclipse-Kotlin-Plugin which works not very well. I now tried it using IntelliJ and it works like expected.
The Eclipse-Plugin isn't maintained afaik. If you have the opportunity use IntelliJ ;-)
It's a little bit sad that using kotlin isn't ide independent. Our development policy is to use Eclipse. So it is impossibe to recommend kotlin to a wider audience. I unterstand that JetBrains want to promote their own ide. But that will slow down or stop the raise of kotlin.
Kotlin itself is ide independent. You can install the kotlin SDK And use kotlinc to compile. The Eclipse plugin for Kotlin is just that...a plugin. It adds Kotlin support to Eclipse. It sounds like it's just not as well maintained though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.