The Difference Between Null, Nothing, Nil, None and Unit in Scala | Rock the JVM

preview_player
Показать описание

This video is for the beginner Scala programmer who comes from another language and might be confused about the different way of expressing the lack of a value. By the end of this video, you'll understand the difference between the null reference, the Null type, Nil, None, Unit and Nothing and will know which is used when. In short:

1. The null reference is used as an absent value - when you access fields or methods you'll get the famous NullPointerException
2. The Null type is the type of the null reference.
3. Nil is the empty List.
4. None is the empty Option.
5. Unit represents "void" from other languages.
6. Nothing is the bottom of the type hierarchy.

We talk more about Nothing on video and on the blog:

Take the free Scala at Light Speed downloadable 2-hour course:

Follow Rock the JVM on:

-------------------------------------------------------------------------
-------------------------------------------------------------------------

Contents:
0:00 intro
1:12 the null reference
2:16 the Null type
5:09 Nil
6:48 None
9:08 Unit
10:50 Nothing
Рекомендации по теме
Комментарии
Автор

I've been programming in scala for 4 years and finally decided I better get to the bottom of these types 😂 this is awesome and so clear!! Thank you!!!!

bugfacedog
Автор

Totally missed the opportunity to make a punny reference to Sum 41

yodaman
Автор

Wow, overwhelmed with 5 types of nothing haha.

randallwalkerdiaz
Автор

Very helpful.
Would be a great addition is you showed some usecases for them which I guess is very challenging for some :D

vontmany
Автор

Very nice video, I think what is missing (maybe) are uses cases, when do we need to use Null, Nothing.

TheProximator
Автор

is scala api null proof? i mean will i have to deal with it when writing my code? why they introduced it when we have Option...

nifaresg