Type ascription

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 Shadman

scala> val p = s:Object
p: Object = Ahmed Shadman

scala>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.156.161