Package org.objenesis
Class ObjenesisBase
- java.lang.Object
-
- org.objenesis.ObjenesisBase
-
- All Implemented Interfaces:
Objenesis
- Direct Known Subclasses:
ObjenesisSerializer
,ObjenesisStd
public class ObjenesisBase extends java.lang.Object implements Objenesis
Base class to extend if you want to have a class providing your own default strategy. Can also be instantiated directly.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentHashMap<java.lang.String,ObjectInstantiator<?>>
cache
Strategy cache.protected InstantiatorStrategy
strategy
Strategy used by this Objenesis implementation to create classes
-
Constructor Summary
Constructors Constructor Description ObjenesisBase(InstantiatorStrategy strategy)
Constructor allowing to pick a strategy and using cacheObjenesisBase(InstantiatorStrategy strategy, boolean useCache)
Flexible constructor allowing to pick the strategy and if caching should be used
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> ObjectInstantiator<T>
getInstantiatorOf(java.lang.Class<T> clazz)
Will pick the best instantiator for the provided class.<T> T
newInstance(java.lang.Class<T> clazz)
Will create a new object without any constructor being calledjava.lang.String
toString()
-
-
-
Field Detail
-
strategy
protected final InstantiatorStrategy strategy
Strategy used by this Objenesis implementation to create classes
-
cache
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,ObjectInstantiator<?>> cache
Strategy cache. Key = Class, Value = InstantiatorStrategy
-
-
Constructor Detail
-
ObjenesisBase
public ObjenesisBase(InstantiatorStrategy strategy)
Constructor allowing to pick a strategy and using cache- Parameters:
strategy
- Strategy to use
-
ObjenesisBase
public ObjenesisBase(InstantiatorStrategy strategy, boolean useCache)
Flexible constructor allowing to pick the strategy and if caching should be used- Parameters:
strategy
- Strategy to useuseCache
- IfObjectInstantiator
s should be cached
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
newInstance
public <T> T newInstance(java.lang.Class<T> clazz)
Will create a new object without any constructor being called- Specified by:
newInstance
in interfaceObjenesis
- Type Parameters:
T
- Type instantiated- Parameters:
clazz
- Class to instantiate- Returns:
- New instance of clazz
-
getInstantiatorOf
public <T> ObjectInstantiator<T> getInstantiatorOf(java.lang.Class<T> clazz)
Will pick the best instantiator for the provided class. If you need to create a lot of instances from the same class, it is way more efficient to create them from the same ObjectInstantiator than callingnewInstance(Class)
.- Specified by:
getInstantiatorOf
in interfaceObjenesis
- Type Parameters:
T
- Type to instantiate- Parameters:
clazz
- Class to instantiate- Returns:
- Instantiator dedicated to the class
-
-