Class ObjenesisBase
java.lang.Object
org.objenesis.ObjenesisBase
- All Implemented Interfaces:
Objenesis
- Direct Known Subclasses:
ObjenesisSerializer, ObjenesisStd
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConcurrentHashMap<String, ObjectInstantiator<?>> Strategy cache.protected final InstantiatorStrategyStrategy used by this Objenesis implementation to create classes -
Constructor Summary
ConstructorsConstructorDescriptionObjenesisBase(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
Modifier and TypeMethodDescription<T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz) Will pick the best instantiator for the provided class.<T> TnewInstance(Class<T> clazz) Will create a new object without any constructor being calledtoString()
-
Field Details
-
strategy
Strategy used by this Objenesis implementation to create classes -
cache
Strategy cache. Key = Class, Value = InstantiatorStrategy
-
-
Constructor Details
-
ObjenesisBase
Constructor allowing to pick a strategy and using cache- Parameters:
strategy- Strategy to use
-
ObjenesisBase
Flexible constructor allowing to pick the strategy and if caching should be used- Parameters:
strategy- Strategy to useuseCache- IfObjectInstantiators should be cached
-
-
Method Details
-
toString
-
newInstance
Will create a new object without any constructor being called- Specified by:
newInstancein interfaceObjenesis- Type Parameters:
T- Type instantiated- Parameters:
clazz- Class to instantiate- Returns:
- New instance of clazz
-
getInstantiatorOf
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:
getInstantiatorOfin interfaceObjenesis- Type Parameters:
T- Type to instantiate- Parameters:
clazz- Class to instantiate- Returns:
- Instantiator dedicated to the class
-