louiscad
12/15/2020, 10:30 PMwhere
clause that specifies type arguments constraints for a function.
I think that would satisfy many use cases where we currently write multiple functions (often extensions).
The when
expression would also need to be tweaked to make use of this I think, and probably some compiler magic, and maybe @JvmOverloads
, unless these functions are required to have the union type constrained generic argument to be reified
, which requires the function to be inline
, and always inlining the code.Iaroslav Postovalov
12/16/2020, 8:55 AMinline fun <reified T> T.printIntOrString() where T : Int or String = when (this) {
is Int -> print("int! $this")
is String -> print ("string. $this")
}
Iaroslav Postovalov
12/16/2020, 8:56 AMalexsullivan114
12/16/2020, 3:18 PMjw
12/16/2020, 5:25 PMlouiscad
12/16/2020, 5:27 PMAstronaut4449
12/18/2020, 10:40 PMlouiscad
12/19/2020, 11:13 AMAstronaut4449
12/19/2020, 11:22 AM