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 …
- Book Review: Murach’s Java Servlets And JSP 3rd Edition September 23, 2014
- Book Review: RESTful Web Services with Dropwizard by Alexandros Dallas September 8, 2014
- Book Review: RabbitMQ Essentials by David Dossot September 7, 2014
- Parameterized Test Runner in JUnit August 25, 2014
- Simple Aspect Oriented Programming (AOP) using CDI in JavaEE August 24, 2014
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.