diesieben07
08/04/2017, 12:48 PMas T
is an unchecked cast, it does not actually do any check, it says "ok I'll assume this is a T now".aballano
08/04/2017, 12:48 PMnull as String
it will crashdiesieben07
08/04/2017, 12:49 PMString
is a concrete type. T
is a type parameter, it could be any type, it's erased.T
could be String?
, too.aballano
08/04/2017, 12:50 PMassertThat(Intent().getSerializableOrDefault<ASerializableClass>("a", default)).isEqualTo(default)
that still worksdiesieben07
08/04/2017, 12:50 PMgetSerializableOrDefault
the compiler does not know that.T
is, so you cannot check for it.aballano
08/04/2017, 12:54 PMdiesieben07
08/04/2017, 12:55 PMgetSerializableOrDefault
method looks like this:
fun Intent.getSerializableOrDefault(name: String, default: Any?)
as T
does nothing at runtime. There is no actual type-check performed.trevjones
08/04/2017, 12:55 PMT?
so that it is more clearaballano
08/04/2017, 12:55 PMdiesieben07
08/04/2017, 12:56 PMaballano
08/04/2017, 12:56 PMas? T
or as T?
, but Take is still righttrevjones
08/04/2017, 1:05 PM