Marc Knaup
02/07/2020, 8:45 AMinline fun <R> Any.toIntOrElse(elseBlock: () -> R): R where Int: R = …
should allow Int
, Int?
, Any
and Any?
as R
.stantronic
02/07/2020, 10:56 AMMarc Knaup
02/07/2020, 10:57 AMDico
02/07/2020, 3:10 PMwhere Int : R
part?Dico
02/07/2020, 3:11 PMMarc Knaup
02/07/2020, 3:34 PMR
is nullable then the result of the function becomes nullable too.
Or if I want to return for example Number
in the else block the result widens from Int
to Number
.
If you have Int
the benefits of widening are limited, but they larger the hierarchy the more useful it becomes.
Nullable vs. non-nullable is main use-case though. I ran into that problem several times now.Dico
02/07/2020, 4:12 PMDico
02/07/2020, 4:12 PMNumber
instead of Int
then the result should simply be Number
.Dico
02/07/2020, 4:13 PMAny
instead of Number
Dico
02/07/2020, 4:17 PMfun <R, T> Any.toIntOrElse(elseBlock: () -> R): R
where T : R, T : Int {...}
Marc Knaup
02/08/2020, 8:22 AMType parameter cannot have any other bounds if it’s bounded by another type parameter
Dico
02/08/2020, 8:23 AM