This decompiles as ``` List listOfDouble = Co...
# announcements
m
This decompiles as
Copy code
List listOfDouble = CollectionsKt.listOf(1.0D);
      if (listOfDouble == null) {
         throw new TypeCastException("null cannot be cast to non-null type kotlin.collections.List<kotlin.Int>");
      } else {
         int first = ((Number)listOfDouble.get(0)).intValue();
         System.out.println("first=" + first + " (" + Integer.TYPE.getName() + ')');
      }
p
So the reason the cast is not failing is due to the unboxing?
m
No idea. From my understanding, a conversion from Double to Int is made which is different from a cast
A cast would have most likely failed
But really not sure what's happening
p
I think it's attempting to do a conversion from
Integer
to
int
but through a cast to the
Number
superclass to invoke the
intValue()
method. Because of this it's actually casting the boxed
Double
value to
Number
(which succeeds) instead of the expected cast of the
Double
to
Integer
which would fail
d
The conversion from boxed Int to Int is identical to the conversion from boxed Double to Int because it uses Number superclass.
Ok what Phil said
m
I see. That feels weird though
d
Weird things can happen when you cast generic type parameters. It's not advisable.