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 SummaryModifier 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.GroovyObjectSupportgetMetaClass, setMetaClassMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, wait
- 
Method Details- 
getNullObjectReturns the NullObject reference.- Returns:
- the null object
 
- 
clonepublic java.lang.Object clone()Since this is implemented as a singleton, avoid the use of the clone method.- Overrides:
- clonein class- java.lang.Object
- Returns:
- never
- Throws:
- java.lang.NullPointerException
 
- 
equalspublic boolean equals(java.lang.Object o)null is only equal to null.- Overrides:
- equalsin class- java.lang.Object
- Parameters:
- o- the reference object with which to compare
- Returns:
- true if this object is the same as the to argument
 
- 
hashCodepublic int hashCode()- Overrides:
- hashCodein class- java.lang.Object
- Returns:
- never
- Throws:
- java.lang.NullPointerException
 
- 
toStringpublic java.lang.String toString()- Overrides:
- toStringin class- java.lang.Object
 
- 
getPropertypublic 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
 
- 
setPropertypublic 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 interest
- value- the new value for the property
- Throws:
- java.lang.NullPointerException
 
- 
invokeMethodpublic 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 call
- arguments- the arguments to use for the method call
- Returns:
- never
- Throws:
- java.lang.NullPointerException
 
- 
asBooleanpublic boolean asBoolean()A null object coerces to false.- Returns:
- false
 
- 
asTypepublic java.lang.Object asType(java.lang.Class c)Type conversion method for null.- Returns:
- null
 
- 
ispublic boolean is(java.lang.Object o)Tests for equal references.- Returns:
- true if object is null
 
- 
iteratorpublic java.util.Iterator iterator()Provides ability to iterate on null.- Returns:
- an empty iterator
 
- 
pluspublic 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
 
- 
pluspublic 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
 
- 
withAllows the closure to be called for NullObject.- Parameters:
- closure- the closure to call on the object
- Returns:
- result of calling the closure
 
 
-