Union types

With real union type, you can have

fun foo(x : String|Number) = TODO()

fun foo1(y : String|Number|LocalDate) : Unit {
    if (y !is LocalDate) {  // so y is String|Number
        foo(y);
    }
}

Not the case with function defined as

fun foo(x : StringOrNumber) = TODO()

fun foo1(y : StringOrNumberOrLocalDate) : Unit { ... }

since StringOrNumber is not related with StringOrNumberOrLocalDate

2 Likes