Skip to content

Commit 68ecad8

Browse files
authored
Add minor explanation about List are homogeneous (#56)
1 parent 7d116d7 commit 68ecad8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/scala/scalatutorial/sections/StandardLibrary.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ object StandardLibrary extends ScalaTutorialSection {
2424
*
2525
* - Lists are immutable --- the elements of a list cannot be changed,
2626
* - Lists are recursive (as you will see in the next subsection),
27-
* - Lists are ''homogeneous'': the elements of a list must all have the
28-
* same type.
27+
* - Lists are ''homogeneous'': A list is intended to be composed of elements that all have the same type.
28+
*
29+
* That's because when you create a `List` of elements with different types it will look for a common ancestor.
30+
* The common ancestor for all types is `Any`
31+
*
32+
* {{{
33+
* val heterogeneousList: List[Any] = List(1, "1", '1')
34+
* }}}
2935
*
3036
* The type of a list with elements of type `T` is written `List[T]`:
3137
*

0 commit comments

Comments
 (0)