tschuchort
05/14/2018, 6:36 PMCzar
05/14/2018, 6:49 PMtschuchort
05/14/2018, 7:02 PMMutableList
) lead to an error? Whether I declare a MutableList<Int>
and concat it with a MutableList<Double>
to get a MutableList<Number>
or declare it as a MutableList<Number>
initialized with only `Int`s, then insert a bunch of `Double`s doesn't make a differencearaqnid
05/14/2018, 10:38 PMMutableList<Int>
and MutableList<Double>
to get a MutableList<Number>
, what do you expect to happen when you add a BigDecimal
to it?tschuchort
05/15/2018, 8:12 AMMutableList<Number>
since BigDecimal
is a Number
. The list only stores references and the generic type is erased, so in fact I can put any object in it, as long as I don't declare it as a `MutableList<Int>`:
val list1: MutableList<Number> = MutableList<Int>(1,2,3,4,5).concat(MutableList<Double>(1.1, 2.2, 3.3)) // ok
val list2 = MutableList<Int>(1,2,3,4,5) // ok
(list2 as MutableList<Double>) += 1.1 // ok
list2.map(::functionForInts) // not ok
araqnid
05/15/2018, 10:57 AM(list2 as MutableList<Double>) += 1.1
is not really ok, it doesn't make sense, just the runtime is deficient and allows it.