Up until now I have been using this Kotlin sealed class:
sealed class ScanAction {
class Continue: ScanAction()
class Stop: ScanAction()
... /* There's more but that's not super important */
}
Which has been working great in both my Kotlin and Java code. Today I tried changing this class to use objects instead (as is recommended to reduce extra class instantiation):
sealed class ScanAction {
object Continue: ScanAction()
object Stop: ScanAction()
}
I am able to reference this easy peasy in my other Kotlin files, but I am now struggling to use it in my Java files.
I have tried the following and both of these kick back compilation errors when trying to make reference to in Java:
ScanAction test = ScanAction.Continue;
ScanAction test = new ScanAction.Continue();
Does anyone know how I can reference the instance in Java now?
You have to use the INSTANCE
property:
ScanAction test = ScanAction.Continue.INSTANCE;