Null, null, Nil, Nothing, None, and Unit in Scala

Posted on July 12, 2009. Filed under: Scala | Tags: , , , , , , , |

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.


Read Full Post | Make a Comment ( 2 so far )

Recently on Java PitStop...

Traits in Scala- Deep Dive

Posted on July 11, 2009. Filed under: Scala | Tags: , , , |

How’s Scala different from Java?

Posted on July 5, 2009. Filed under: Scala | Tags: , , |

Control Structures in Scala- A brief overview

Posted on July 3, 2009. Filed under: Scala | Tags: , , , , , , |

Tuples- Returning multiple values in Scala

Posted on July 3, 2009. Filed under: Scala | Tags: , , , |

“val” versus “var” Declarations in Scala

Posted on July 2, 2009. Filed under: Scala | Tags: , , , , |

Monitoring and Profiling using VisualVM-1

Posted on June 22, 2009. Filed under: General Java, Java Basics | Tags: , , , , , , |

My JavaFX Application

Posted on June 6, 2009. Filed under: JavaFX | Tags: , , |

Selection Sort: Brute Force approach to sorting with example in Groovy

Posted on May 5, 2009. Filed under: Algorithms | Tags: , , , , |

Core Java Refcardz by Cay S. Horstmann

Posted on November 12, 2008. Filed under: Articles | Tags: , , , |

Vote for your IDE: Best IDE for Java Application Development

Posted on October 20, 2008. Filed under: General Java, IDE | Tags: , , |

Liked it here?
Why not try sites on the blogroll...