In Ceylon, an
if (is Nil|File fileResource) {
...
}
construct, or like this:
Object obj = … ;
if (is Hello obj) {
obj.say();
}
by narrowing the type of an object reference simply like this, we can very expressively narrow an object type reference in an easily readable manner.
What (could) be the Kotlin’s equivalent of a syntax like this, which’d then even be used as a better syntax even for union types
too, to allow a variable to have more than one type. Like:
shared void integerOrString(Integer|String input) {
if (is Integer input) {
print("Got the integer ``input``");
} else {
print("Got the string '``input``'");
}
}