NullObject (Groovy 5.0.8)
Description: declaration: package: org.codehaus.groovy.runtime, class: NullObject

Package org.codehaus.groovy.runtime

# Class NullObject

java.lang.Object
groovy.lang.GroovyObjectSupport
org.codehaus.groovy.runtime.NullObject

All Implemented Interfaces:
  `GroovyObject`

public class NullObject extends GroovyObjectSupport

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `asBoolean()`
  A null object coerces to false.
  `Object`
  `asType(Class c)`
  Type conversion method for null.
  `Object`
  `clone()`
  Since this is implemented as a singleton, avoid the use of the clone method.
  `boolean`
  `equals(Object o)`
  null is only equal to null.
  `static NullObject`
  `getNullObject()`
  Returns the NullObject reference.
  `Object`
  `getProperty(String name)`
  Tries to get a property on null, which fails except for "class" and "metaClass".
  `int`
  `hashCode()`
  `Object`
  `invokeMethod(String name, Object arguments)`
  Tries to invoke a method on null, which fails.
  `boolean`
  `is(Object o)`
  Tests for equal references.
  `Iterator`
  `iterator()`
  iterator() method to be able to iterate on null.
  `Object`
  `plus(Object o)`
  Fallback for `null+null`.
  `Object`
  `plus(String s)`
  Allows to add a String to null.
  `void`
  `setProperty(String name, Object value)`
  Tries to set a property on null, which fails.
  `String`
  `toString()`
  `<T> T`
  `with(Closure<T> closure)`
  Deprecated.

  ### Methods inherited from class groovy.lang.GroovyObjectSupport

  `getMetaClass, setMetaClass`

  ### Methods inherited from class java.lang.Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## 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 fails.
    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(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