Null- Its a Trait.
null- Its an instance of Null- Similar to Java null.
Nil- Represents an emptry List of anything of zero length. Its not that it refers to nothing but it refers to List which has no contents.
Nothing is a Trait. Its 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.
Note: Any is supertype of AnyRef and AnyVal. AnyRef is the supertype of all the reference classes (like String, List, Iterable) in scala. AnyVal is the supertype of all the value classes (like Int, Float, Double, Byte, Short..). Null is a subtype of all the reference classes. null is its only instance. Nothing is subtype of every other type i.e of reference and value classes.
Think- AnyRef == Object in Java.
The above is a breif summary of a wonderful post by Matt Malone where he has explained all these concepts in depth with examples. Read the blog post here.
No related posts.
Connect to us …
- Simple Aspect Oriented Programming (AOP) using CDI in JavaEE August 24, 2014
- Book Review: Java Performance by Charlie Hunt and Binu John August 20, 2014
- Getting started with Mocking in Java using Mockito February 23, 2014
- Another sample for using JAXB November 24, 2013
- Book Review: Peopleware October 25, 2013
Some of the links contained within this site have my referral id, which provides me with a small commission for each sale. Thank you for your support.