Undefined
Utility class that creates unique undefined
values for any class.
These undefined
values are typically used as default values of parameters in ktorm-ksp generated pseudo constructor functions for entities. Pseudo constructors check if the parameter is referential identical to the undefined
value to judge whether it is manually assigned by users or not. We don't use null
in this case because null
can also be a valid value for entity properties.
For example:
public fun Employee(name: String? = Undefined.of()): Employee {
val entity = Entity.create<Employee>()
if (name !== Undefined.of<String>()) {
entity.name = name
}
return entity
}
In this example, Employee("vince")
creates an employee named vince, Employee(null)
creates an employee with null name (can also be valid in some cases), and, in the meanwhile, Employee()
creates an employee without giving a name, which is different with Employee(null)
.
Note: undefined
values created by this class can only be used for referential comparing, any method invocation on these values can cause exceptions.