The first list is of type List[Double] due to the extension of the letter type. Scala sees literals and notes that although they are of different types, they can be combined by expanding some of them. If there was no type extension, then the most common AnyVal superclass will be accepted.
List(1.1 ), 3 )
The second list is explicitly List[Int] , although an explicit call to Double will result in a type extension for literals.
List(5 , 7 )
Now, itβs important to note that type expansion is what happens at compile time. Compiled code will not contain Int 3, only Double 3.0. However, when the list was created, a type extension is not possible, since the stored objects are essentially different.
So, as soon as you separate the two lists, the resulting type will be the superclass Double and Int . Namely, AnyVal . However, as a result of the Java interaction, AnyVal cannot contain useful methods (such as numerical operators).
I am wondering what makes Clojure inside. Does integers convert to double parts when concatenated? Or does it store everything as an Object (e.g., Scala), but has smarter math operators?
source share