Class NullObject

java.lang.Object
groovy.lang.GroovyObjectSupport
org.codehaus.groovy.runtime.NullObject
All Implemented Interfaces:
GroovyObject

public class NullObject extends GroovyObjectSupport
  • Method Details

    • getNullObject

      public static NullObject getNullObject()
      Returns the NullObject reference.
      Returns:
      the null object
    • clone

      public Object clone()
      Since this is implemented as a singleton, avoid the use of the clone method.
      Overrides:
      clone in class Object
      Returns:
      never
      Throws:
      NullPointerException
    • equals

      public boolean equals(Object o)
      null is only equal to null.
      Overrides:
      equals in class Object
      Parameters:
      o - the reference object with which to compare
      Returns:
      true if this object is the same as the to argument
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      never
      Throws:
      NullPointerException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getProperty

      public Object getProperty(String name)
      Tries to get a property on null, which fails except for "class" and "metaClass".
      Parameters:
      name - the name of the property of interest
      Returns:
      never
      Throws:
      NullPointerException
    • setProperty

      public void setProperty(String name, Object value)
      Tries to set a property on null, which fails.
      Parameters:
      name - the name of the property of interest
      value - the new value for the property
      Throws:
      NullPointerException
    • invokeMethod

      public Object invokeMethod(String name, Object arguments)
      Tries to invoke a method on null, which will always fail.
      Parameters:
      name - the name of the method to call
      arguments - the arguments to use for the method call
      Returns:
      never
      Throws:
      NullPointerException
    • asBoolean

      public boolean asBoolean()
      A null object coerces to false.
      Returns:
      false
    • asType

      public Object asType(Class c)
      Type conversion method for null.
      Returns:
      null
    • is

      public boolean is(Object o)
      Tests for equal references.
      Returns:
      true if object is null
    • iterator

      public Iterator iterator()
      iterator() method to be able to iterate on null. Note: this part is from Invoker
      Returns:
      an empty iterator
    • plus

      public Object plus(Object o)
      Fallback for null+null. The plus(java.lang.String) variant catches the case of adding a non-null String to null.
      Returns:
      never
      Throws:
      NullPointerException
    • plus

      public Object plus(String s)
      Allows to add a String to null. The result is concatenated String of the result of calling toString() on this object and the String in the parameter.
      Returns:
      the concatenated string
    • with

      @Deprecated(since="5.0.0") public <T> T with(Closure<T> closure)
      Deprecated.
      Allows the closure to be called for NullObject.
      Parameters:
      closure - the closure to call on the object
      Returns:
      result of calling the closure