jstuyts-squins
01/17/2018, 3:54 PMa
is also an Any
, but the compiler will use the most specific type of the variable, which is A
. By explicitly declaring the type to be Any
for aAsAny
, the compiler may no longer assume it is an A
, so it has to allow the comparison using ==
. Yes, it would be possible to deduce that the actual type of aAsAny
is always an A
in this code, but that would change the semantics of the language: I am going to allow comparison of Any
and Int
, except for when I am able to determine that the actual type cannot be compared to Int