top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Differentiate these terms in Scala: Null, null, Nil, Nothing, None, and Unit?

+1 vote
704 views
Differentiate these terms in Scala: Null, null, Nil, Nothing, None, and Unit?
posted Aug 3, 2016 by Karthick.c

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Hi Karthick,All those terms are defined and differentiated as follows:
Null– Its a Trait.
null– Its an instance of Null- Similar to Java null.

Nil– Represents an emptey List of anything of zero length. It's not that it refers to nothing but it refers to List which has no contents.

Nothing - is a Trait. It's a subtype of everything. But not superclass of anything. There are no instances of Nothing.

None– Used to represent a sensible return value. Just to avoid null pointer exception. Option has exactly 2 subclasses- Some and None. None signifies no result from the method.

Unit– Type of method that doesn’t return a value of anys sort.

answer Aug 5, 2016 by Shivam Kumar Pandey
...