Package org.codehaus.groovy.runtime
Class NullObject
java.lang.Object
groovy.lang.GroovyObjectSupport
org.codehaus.groovy.runtime.NullObject
- All Implemented Interfaces:
- GroovyObject
- 
Method SummaryModifier and TypeMethodDescriptionbooleanA null object always coerces to false.Type conversion method for null.clone()Since this is implemented as a singleton, we should avoid the use of the clone methodbooleannull is only equal to nullstatic NullObjectget the NullObject referencegetProperty(String property) Tries to get a property on null, which will always failinthashCode()invokeMethod(String name, Object args) Tries to invoke a method on null, which will always failbooleanThe method "is" is used to test for equal references.iterator()iterator() method to be able to iterate on null.Fallback for null+null.Allows to add a String to null.voidsetProperty(String property, Object newValue) Tries to set a property on null, which will always failtoString()<T> TAllows the closure to be called for NullObjectMethods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClass
- 
Method Details- 
getNullObjectget the NullObject reference- Returns:
- the null object
 
- 
cloneSince this is implemented as a singleton, we should avoid the use of the clone method
- 
getPropertyTries to get a property on null, which will always fail- Parameters:
- property- - the property to get
- Returns:
- a NPE
 
- 
withAllows the closure to be called for NullObject- Parameters:
- closure- the closure to call on the object
- Returns:
- result of calling the closure
 
- 
setPropertyTries to set a property on null, which will always fail- Parameters:
- property- - the property to set
- newValue- - the new value of the property
 
- 
invokeMethodTries 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
 
- 
equalsnull is only equal to null
- 
iteratoriterator() method to be able to iterate on null. Note: this part is from Invoker- Returns:
- an iterator for an empty list
 
- 
plusAllows 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
 
- 
plusFallback 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
 
- 
isThe 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
 
- 
asTypeType conversion method for null.- Parameters:
- c- - the class to convert to
- Returns:
- always null
 
- 
asBooleanpublic boolean asBoolean()A null object always coerces to false.- Returns:
- false
 
- 
toString
- 
hashCodepublic int hashCode()
 
-