class Foo(val param1: String, var param2: Int) {
// class body
companion object {
val NULL = Foo("", 0)
}
}
Is the NULL object valid in Kotlin?
Although Kotlin allows adding default values in the constructor, is there a reason for NULL object to be discouraged, like in the above snippet?
Lets, say I don't need to allow constructing objects just with one param like: Foo("ABC") or Foo(5). (...after modifying the Foo to have default values in the constructor that is)
You can create a factory function without parameters that will return a null object: