ConstantInitializer¶
- public class org.apache.commons.lang3.concurrent.ConstantInitializer<T> implements ConcurrentInitializer<T>[source]¶
A very simple implementation of the
ConcurrentInitializerinterface which always returns the same object.An instance of this class is passed a reference to an object when it is constructed. The
#get()method just returns this object. No synchronization is required.This class is useful for instance for unit testing or in cases where a specific object has to be passed to an object which expects a
ConcurrentInitializer.- Parameters:
<T> – The type of the object managed by this initializer
- Since:
3.0
Constructors¶
Creates a new instance of |
- public ConstantInitializer(T obj)[source]¶
Creates a new instance of
ConstantInitializerand initializes it with the object to be managed. Theget()method will always return the object passed here. This class does not place any restrictions on the object. It may benull, thenget()will returnnull, too.- Parameters:
obj – The object to be managed by this initializer
Methods¶
Compares this object with another one. |
|
Gets the object managed by this initializer. |
|
Gets the object passed to the constructor. |
|
Returns a hash code for this object. |
|
Tests whether this initializer is initialized. |
|
Returns a string representation for this object. |
- @Override public boolean equals(Object obj)[source]¶
Compares this object with another one. This implementation returns true if and only if the passed in object is an instance of
ConstantInitializerwhich refers to an object equals to the object managed by this instance.- Parameters:
obj – The object to compare to
- Returns:
A flag whether the objects are equal
- @Override public T get() throws ConcurrentException[source]¶
Gets the object managed by this initializer. This implementation just returns the object passed to the constructor.
- Returns:
The object managed by this initializer
- Throws:
org.apache.commons.lang3.concurrent.ConcurrentException – Thrown if an error occurs.
- public final T getObject()[source]¶
Gets the object passed to the constructor. This is the same object returned by
get(), but this method does not declare a checked exception.- Returns:
The object managed by this initializer
- @Override public int hashCode()[source]¶
Returns a hash code for this object. This implementation returns the hash code of the managed object.
- Returns:
A hash code for this object