does kotlin support anon union types (e.g. String ...
# announcements
b
does kotlin support anon union types (e.g. String | Int)
👍 1
b
No currently not But I think it would be a great addition to the type system
i
I am not so sure. In general I have seen only one useful example for union types and Kotlin. Can you provide few examples where union types would provide value?
👍 1
b
mostly when compiling down to javascript
you have to deal with functions that can return different types
example: return object on success or false on failure, which certainly is bad practice but nonetheless cases like this exist in js
in Kotlin you probably would have to wrap these two types in a sealed class
👍 1
sealed class ScreenfullType { class Actual(val obj: ScreenFull); class DoesNotExist}
I suppose
i
Honestly I don’t see a point of pouting the core language only because one of the targets had bad architecture. These ScreenFull classes seems to be doing correct thing by abstracting bad code 🤔 BTW For JS as a target you could also use
dynamic
type (I know it’s far from perfect) https://kotlinlang.org/docs/reference/dynamic-type.html
b
right, that's the first use case that comes to my mind
t
have fun reading (rabbit hole): https://youtrack.jetbrains.com/issue/KT-13108 but it does not seem unions will land anytime soon
👍 1
h
Just have Any refference and a variable for keeping info of what type the object is