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 booleanasBoolean()A null object coerces to false.java.lang.ObjectasType(java.lang.Class c)Type conversion method for null.java.lang.Objectclone()Since this is implemented as a singleton, avoid the use of the clone method.booleanequals(java.lang.Object o)null is only equal to null.static NullObjectgetNullObject()Returns the NullObject reference.java.lang.ObjectgetProperty(java.lang.String name)Tries to get a property on null, which fails.inthashCode()java.lang.ObjectinvokeMethod(java.lang.String name, java.lang.Object arguments)Tries to invoke a method on null, which falis.booleanis(java.lang.Object o)Tests for equal references.java.util.Iteratoriterator()Provides ability to iterate on null.java.lang.Objectplus(java.lang.Object o)Fallback fornull+null.java.lang.Objectplus(java.lang.String s)Allows to add a String to null.voidsetProperty(java.lang.String name, java.lang.Object value)Tries to set a property on null, which fails.java.lang.StringtoString()<T> Twith(Closure<T> closure)Allows the closure to be called for NullObject.Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClassMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Method Details
-
getNullObject
Returns the NullObject reference.- Returns:
- the null object
-
clone
public java.lang.Object clone()Since this is implemented as a singleton, avoid the use of the clone method.- Overrides:
clonein classjava.lang.Object- Returns:
- never
- Throws:
java.lang.NullPointerException
-
equals
public boolean equals(java.lang.Object o)null is only equal to null.- Overrides:
equalsin classjava.lang.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:
hashCodein classjava.lang.Object- Returns:
- never
- Throws:
java.lang.NullPointerException
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
getProperty
public java.lang.Object getProperty(java.lang.String name)Tries to get a property on null, which fails.- Parameters:
name- the name of the property of interest- Returns:
- never
- Throws:
java.lang.NullPointerException
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object value)Tries to set a property on null, which fails.- Parameters:
name- the name of the property of interestvalue- the new value for the property- Throws:
java.lang.NullPointerException
-
invokeMethod
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object arguments)Tries to invoke a method on null, which falis.- Parameters:
name- the name of the method to callarguments- the arguments to use for the method call- Returns:
- never
- Throws:
java.lang.NullPointerException
-
asBoolean
public boolean asBoolean()A null object coerces to false.- Returns:
- false
-
asType
public java.lang.Object asType(java.lang.Class c)Type conversion method for null.- Returns:
- null
-
is
public boolean is(java.lang.Object o)Tests for equal references.- Returns:
- true if object is null
-
iterator
public java.util.Iterator iterator()Provides ability to iterate on null.- Returns:
- an empty iterator
-
plus
public java.lang.Object plus(java.lang.Object o)Fallback fornull+null. Theplus(java.lang.String)variant catches the case of adding a non-null String to null.- Returns:
- never
- Throws:
java.lang.NullPointerException
-
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.- Returns:
- the concatenated string
-
with
Allows the closure to be called for NullObject.- Parameters:
closure- the closure to call on the object- Returns:
- result of calling the closure
-