You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Scala, all values have a type, including numerical values and functions. The diagram below illustrates a subset of the type hierarchy.
16
16
17
-

17
+
<ahref="/tutorials/tour/unified-types-diagram.svg"><imgstyle="width:100%"src="/tutorials/tour/unified-types-diagram.svg"alt="Scala Type Hierarchy"></a>
18
18
19
19
## Scala Type Hierarchy ##
20
20
@@ -49,23 +49,29 @@ c
49
49
true
50
50
<function>
51
51
```
52
+
52
53
## Type Casting
53
54
Value types can be cast in the following way:
54
-

55
+
<ahref="/tutorials/tour/type-casting-diagram.svg"><imgstyle="width:100%"src="/tutorials/tour/type-casting-diagram.svg"alt="Scala Type Hierarchy"></a>
56
+
55
57
For example:
58
+
56
59
```tut
57
60
val x: Long = 987654321
58
61
val y: Float = x // 9.8765434E8 (note that some precision is lost in this case)
59
62
60
63
val face: Char = '☺'
61
64
val number: Int = face // 9786
62
65
```
66
+
63
67
Casting is unidirectional. This will not compile:
68
+
64
69
```
65
70
val x: Long = 987654321
66
71
val y: Float = x // 9.8765434E8
67
72
val z: Long = y // Does not conform
68
73
```
74
+
69
75
You can also cast a reference type to a subtype. This will be covered later in the tour.
0 commit comments