Kroppeb
05/30/2019, 8:10 PMas? TArgument
give an Unchecked cast
warningShawn
05/30/2019, 8:11 PMKroppeb
05/30/2019, 8:13 PMfun <TArgument:Any> ArgumentParser<TArgument>.value(): TArgument?{
return arguments[this] as? TArgument
}
Kroppeb
05/30/2019, 8:13 PMas?
was a safe cast?karelpeeters
05/30/2019, 8:17 PMkarelpeeters
05/30/2019, 8:18 PMstreetsofboston
05/30/2019, 8:19 PMas?
should safely return null
if the cast failsShawn
05/30/2019, 8:20 PMstreetsofboston
05/30/2019, 8:20 PMTo avoid an exception being thrown, one can use a safe cast operator as? that returns null on failure
karelpeeters
05/30/2019, 8:20 PMfun ArgumentParser<Any?>.value(): Any?{
return arguments[this]
}
karelpeeters
05/30/2019, 8:20 PMTArgument
? It doesn't even know about it.streetsofboston
05/30/2019, 8:21 PMTArgument
as a type, not as a generic type.
Thanks!streetsofboston
05/30/2019, 8:22 PMas?
but about the return-type vs the type that is actually returned. 🙂Kroppeb
05/30/2019, 8:22 PMKroppeb
05/30/2019, 8:23 PMKroppeb
05/30/2019, 8:23 PMas? TArgument
Kroppeb
05/30/2019, 8:24 PMArgumentParser<T> -> T
streetsofboston
05/30/2019, 8:24 PMarguments[this]
. Make the type reified:
inline fun <reified TArgument:Any> ArgumentParser<TArgument>.value(): TArgument? { ... }
karelpeeters
05/30/2019, 8:25 PMKroppeb
05/30/2019, 8:26 PMarguments
has to be public no?streetsofboston
05/30/2019, 8:26 PMkarelpeeters
05/30/2019, 8:26 PM@PusblishedApi
.Kroppeb
05/30/2019, 8:26 PMstreetsofboston
05/30/2019, 8:27 PM@PublishedApi
doesn’t work on private
, only on internal
scope…karelpeeters
05/30/2019, 8:27 PMreified
.Dico
05/30/2019, 9:46 PMas
on a type parameter.karelpeeters
05/30/2019, 10:10 PMDico
05/31/2019, 1:50 AMkarelpeeters
05/31/2019, 7:49 AMfun <T: Any> foo() {
null as? T //succeeds
null as T //fails
}