Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.runtime
[Java] Class NullObject

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

    public class NullObject
    extends GroovyObjectSupport

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

Methods inherited from class GroovyObjectSupport
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Method Detail

### asBoolean

    public boolean asBoolean()

  A null object always coerces to false.
  Returns:
    false

### asType

    public java.lang.Object asType(java.lang.Class c)

  Type conversion method for null.
  Parameters:
    `c` - - the class to convert to
  Returns:
    always null

### clone

    public java.lang.Object clone()

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

### equals

    public boolean equals(java.lang.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

### getNullObject

    public static NullObject getNullObject()

  get the NullObject reference
  Returns:
    the null object

### getProperty

    public java.lang.Object getProperty(java.lang.String property)

  Tries to get a property on null, which will always fail
  Parameters:
    `property` - - the property to get
  Returns:
    a NPE

### hashCode

    public int hashCode()

### invokeMethod

    public java.lang.Object invokeMethod(java.lang.String name, java.lang.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

### is

    public boolean is(java.lang.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

### iterator

    public java.util.Iterator iterator()

  iterator() method to be able to iterate on null. Note: this part is from Invoker
  Returns:
    an iterator for an empty list

### plus

    public java.lang.Object plus(java.lang.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

### plus

    public java.lang.Object plus(java.lang.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

### setProperty

    public void setProperty(java.lang.String property, java.lang.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

### toString

    public java.lang.String toString()

Groovy Documentation