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 SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanasBoolean()A null object always 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, we should avoid the use of the clone methodbooleanequals(java.lang.Object to)null is only equal to nullstatic NullObjectgetNullObject()get the NullObject referencejava.lang.ObjectgetProperty(java.lang.String property)Tries to get a property on null, which will always failinthashCode()java.lang.ObjectinvokeMethod(java.lang.String name, java.lang.Object args)Tries to invoke a method on null, which will always failbooleanis(java.lang.Object other)The method "is" is used to test for equal references.java.util.Iteratoriterator()iterator() method to be able to iterate on null.java.lang.Objectplus(java.lang.Object o)Fallback for null+null.java.lang.Objectplus(java.lang.String s)Allows to add a String to null.voidsetProperty(java.lang.String property, java.lang.Object newValue)Tries to set a property on null, which will always failjava.lang.StringtoString()<T> Twith(Closure<T> closure)Allows the closure to be called for NullObject- 
Methods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClass
 
- 
 
- 
- 
- 
Method Detail- 
getNullObjectpublic static NullObject getNullObject() get the NullObject reference- Returns:
- the null object
 
 - 
clonepublic java.lang.Object clone() Since this is implemented as a singleton, we should avoid the use of the clone method- Overrides:
- clonein class- java.lang.Object
 
 - 
getPropertypublic java.lang.Object getProperty(java.lang.String property) Tries to get a property on null, which will always fail- Specified by:
- getPropertyin interface- GroovyObject
- Overrides:
- getPropertyin class- GroovyObjectSupport
- Parameters:
- property- - the property to get
- Returns:
- a NPE
 
 - 
withpublic <T> 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
 
 - 
setPropertypublic void setProperty(java.lang.String property, java.lang.Object newValue)Tries to set a property on null, which will always fail- Specified by:
- setPropertyin interface- GroovyObject
- Overrides:
- setPropertyin class- GroovyObjectSupport
- Parameters:
- property- - the proprty to set
- newValue- - the new value of the property
 
 - 
invokeMethodpublic java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)Tries to invoke a method on null, which will always fail- Specified by:
- invokeMethodin interface- GroovyObject
- Overrides:
- invokeMethodin class- GroovyObjectSupport
- Parameters:
- name- the name of the method to invoke
- args- - arguments to the method
- Returns:
- a NPE
 
 - 
equalspublic boolean equals(java.lang.Object to) null is only equal to null- Overrides:
- equalsin class- java.lang.Object
- Parameters:
- to- - the reference object with which to compare
- Returns:
- - true if this object is the same as the to argument
 
 - 
iteratorpublic 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
 
 - 
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.- Parameters:
- s- - the String to concatenate
- Returns:
- the concatenated string
 
 - 
pluspublic 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
 
 - 
ispublic 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
 
 - 
asTypepublic java.lang.Object asType(java.lang.Class c) Type 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
 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 
- 
 
-