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 …
- 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
- JSON Processing support in JavaEE 7 and JSR-353 October 18, 2013
- [Promo]Explore something new this Columbus Day with Packt’s biggest ever sale October 16, 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.