I found this question which implements a null object pattern in Kotlin in a certain way. I usually do it a little different in Java:
class MyClass {
static final MyClass INVALID = new MyClass();
public MyClass() {
// empty
}
}
in this way, I can always use MyClass.INVALID as the null object.
How can I achieve this style in Kotlin?
I fiddled with something like this:
data class MyClass(val id: Int) {
object INVALID: MyClass {
}
}
but that doesn't even compile.