Skip to content

Commit 73d7763

Browse files
committed
tour: type inference: fix tut
1 parent c873656 commit 73d7763

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

_tour/type-inference.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ The parameter for map is `f: A => B`. Because we put integers in the `Seq`, the
5858

5959
It is generally considered more readable to declare the type of members exposed in a public API. Therefore, we recommended that you make the type explicit for any APIs that will be exposed to users of your code.
6060

61-
Also, type inference can sometimes infer a too-specific type, as the following program shows:
61+
Also, type inference can sometimes infer a too-specific type. Suppose we write:
6262

63-
```tut:fail
63+
```tut
6464
var obj = null
65+
```
66+
67+
Then we can't then go on and make this reassignment:
68+
69+
```tut:fail
6570
obj = new AnyRef
6671
```
6772

68-
This program does not compile because the type inferred for variable `obj` is `Null`. Since the only value of that type is `null`, it is impossible to make this variable refer to another value.
73+
It won't compile, because the type inferred for `obj` was `Null`. Since the only value of that type is `null`, it is impossible to assign a different value.

0 commit comments

Comments
 (0)