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
Copy file name to clipboardExpand all lines: tutorials/tour/_posts/2017-02-13-unified-types.md
+17-5Lines changed: 17 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -11,15 +11,15 @@ next-page: classes
11
11
previous-page: basics
12
12
---
13
13
14
-
In Scala, all values are instances of a class, including numerical values and functions. The diagram below illustrates the class hierarchy.
14
+
In Scala, all values are instances of a class, including numerical values and functions. The diagram below illustrates a subset the class hierarchy.
15
15
16
-

16
+

17
17
18
18
## Scala Class Hierarchy ##
19
19
20
-
The superclass of all classes`scala.Any` has two direct subclasses: `scala.AnyVal` and `scala.AnyRef`.
20
+
`scala.Any` is the base type of all types. It defines certain universal methods: `==`, `!=`, `equals`, `hashCode`, `toString`.`scala.Any` has two direct subclasses: `scala.AnyVal` and `scala.AnyRef`.
21
21
22
-
`scala.AnyVal` represents value classes. All value classes are non-nullable and predefined; they correspond to the primitive types of Java-like languages. Note that the diagram above also shows implicit conversions between the value classes.
22
+
`scala.AnyVal` represents value classes. All value classes are non-nullable and predefined; they correspond to the primitive types of Java-like languages: `Byte`, `Short`, `Char`, `Int`, `Long`, `Float`, `Double`, and `Boolean`. Scala adds the `Unit` type which is similar to Java's `void`.
23
23
24
24
`scala.AnyRef` represents reference classes. All non-value classes are defined as reference class. Every user-defined class in Scala implicitly extends `scala.AnyRef`. If Scala is used in the context of a Java runtime environment, `scala.AnyRef` corresponds to `java.lang.Object`.
25
25
@@ -35,7 +35,7 @@ val list: List[Any] = List(
35
35
)
36
36
37
37
list.foreach(element => println(element))
38
-
````
38
+
```
39
39
40
40
It defines a variable `list` of type `List[Any]`. The list is initialized with elements of various types, but they all are instance of `scala.Any`, so you can add them to the list.
41
41
@@ -48,3 +48,15 @@ c
48
48
true
49
49
<function>
50
50
```
51
+
52
+
## Nothing and Null
53
+
`Nothing` is a subtype of all types. There is no value that has type `Nothing`. There are two uses: The first is to signal abnormal termination such as an exception (i.e. it doesn't return). The second type usage is an element type of empty collections (e.g. `Set[Nothing]`).
54
+
55
+
`Null` is a subtype of all subtypes of `AnyRef`. The class name is `Null` but the literal identifier is `null`. You can assign any reference type to null.
0 commit comments