July 2017
Intermediate to advanced
796 pages
18h 55m
English
Type ascription is used to tell the compiler what types you expect out of an expression, from all possible valid types. Consequently, a type is valid if it respects existing constraints, such as variance and type declarations, and it is either one of the types the expression it applies to "is a," or there's a conversion that applies in scope. So, technically, java.lang.String extends java.lang.Object, therefore any String is also an Object. For example:
scala> val s = "Ahmed Shadman" s: String = Ahmed Shadmanscala> val p = s:Object p: Object = Ahmed Shadman scala>
Read now
Unlock full access