2

From what I've read, Scala sealed traits can be used for ENUM like behavior, but they are not as intuitive to use in Java or Kotlin.

Scala code (and Suzy MV)

package com.example

sealed trait Answer
case object Yes extends Answer
case object No extends Answer
case object Maybe extends Answer

Java code to call above Scala

import com.example.Yes$;
Yes$ myAnswer = Yes$.MODULE$;

How do you call this in Kotlin?

drusolis
  • 862
  • 9
  • 21
  • Sealed traits are not enums, but it can be used to achieve an enum-like behavior ([almost](https://pedrorijo.com/blog/scala-enums/)). – Feyyaz Jul 10 '18 at 23:34
  • Corrected the description. I don't know Scala, the devs on my team use it, while I automate tests in Kotlin. Thanks for the info. – drusolis Jul 11 '18 at 19:39
  • Refer to [Why does this Kotlin method have enclosing backticks?](https://stackoverflow.com/q/44149474/6521116) – LF00 Nov 23 '19 at 09:01

1 Answers1

2

Backticks are your friends here!

Kotlin

import com.example.`Yes$`
`Yes$`.`MODULE$`
drusolis
  • 862
  • 9
  • 21