Package: org.codehaus.groovy.runtime

## [Java] Class NullObject

- org.codehaus.groovy.runtime.NullObject

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `Object` | `property`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `boolean` | `asBoolean()` A null object always coerces to false.
    `` | `Object` | `asType(Class c)` Type conversion method for null.
    `` | `Object` | `clone()` Since this is implemented as a singleton, we should avoid the use of the clone method
    `` | `boolean` | `equals(Object to)` null is only equal to null
    `` | `static NullObject` | `getNullObject()` get the NullObject reference
    `` | `Object` | `getProperty(String property)` Tries to get a property on null, which will always fail
    `` | `int` | `hashCode()`
    `` | `Object` | `invokeMethod(String name, Object args)` Tries to invoke a method on null, which will always fail
    `` | `boolean` | `is(Object other)` The method "is" is used to test for equal references.
    `` | `Iterator` | `iterator()` iterator() method to be able to iterate on null.
    `` | `Object` | `plus(String s)` Allows to add a String to null.
    `` | `Object` | `plus(Object o)` Fallback for null+null.
    `` | `void` | `setProperty(String property, Object newValue)` Tries to set a property on null, which will always fail
    `` | `String` | `toString()`
    `<T>` | `T` | `with(Closure<T> closure)` Allows the closure to be called for NullObject

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class GroovyObjectSupport` | `getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty`
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Property Detail

    - #### Object property

  - ### Method Detail

    - #### public boolean asBoolean()

      A null object always coerces to false.

      Returns:
        false

    - #### public Object asType(Class c)

      Type conversion method for null.

      Parameters:
        `c` - - the class to convert to
      Returns:
        always null

    - #### public Object clone()

      Since this is implemented as a singleton, we should avoid the use of the clone method

    - #### public boolean equals(Object to)

      null is only equal to null

      Parameters:
        `to` - - the reference object with which to compare
      Returns:
        - true if this object is the same as the to argument

    - #### public static NullObject getNullObject()

      get the NullObject reference

      Returns:
        the null object

    - #### public Object getProperty(String property)

      Tries to get a property on null, which will always fail

      Parameters:
        `property` - - the property to get
      Returns:
        a NPE

    - #### public int hashCode()

    - #### public Object invokeMethod(String name, Object args)

      Tries to invoke a method on null, which will always fail

      Parameters:
        `name` - the name of the method to invoke
        `args` - - arguments to the method
      Returns:
        a NPE

    - #### public boolean is(Object other)

      The method "is" is used to test for equal references. This method will return true only if the given parameter is null

      Parameters:
        `other` - - the object to test
      Returns:
        true if other is null

    - #### public Iterator iterator()

      iterator() method to be able to iterate on null. Note: this part is from Invoker

      Returns:
        an iterator for an empty list

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

      Parameters:
        `s` - - the String to concatenate
      Returns:
        the concatenated string

    - #### public Object plus(Object o)

      Fallback for null+null. The result is always a NPE. The plus(String) version will catch the case of adding a non null String to null.

      Parameters:
        `o` - - the Object
      Returns:
        nothing

    - #### public void setProperty(String property, Object newValue)

      Tries to set a property on null, which will always fail

      Parameters:
        `property` - - the proprty to set
        `newValue` - - the new value of the property

    - #### public String toString()

    - #### <T> public T with(Closure<T> closure)

      Allows the closure to be called for NullObject

      Parameters:
        `closure` - the closure to call on the object
      Returns:
        result of calling the closure