Top Description Fields Constructors Methods
org.objenesis

public Class ObjenesisBase

extends Object
implements Objenesis
Class Inheritance
All Implemented Interfaces
org.objenesis.Objenesis
Known Direct Subclasses
org.objenesis.ObjenesisSerializer, org.objenesis.ObjenesisStd
Imports
org.objenesis.instantiator.ObjectInstantiator, org.objenesis.strategy.InstantiatorStrategy, java.util.concurrent.ConcurrentHashMap

Base class to extend if you want to have a class providing your own default strategy. Can also be instantiated directly.
Author
Henri Tremblay

Field Summary

Modifier and TypeField and Description
protected ConcurrentHashMap<String, ObjectInstantiator<?>>
cache

Strategy cache.

protected final InstantiatorStrategy
strategy

Strategy used by this Objenesis implementation to create classes

Constructor Summary

AccessConstructor and Description
public
ObjenesisBase(InstantiatorStrategy
Strategy to use
strategy
)

Constructor allowing to pick a strategy and using cache

public
ObjenesisBase(InstantiatorStrategy
Strategy to use
strategy
,
boolean
If ObjectInstantiators should be cached
useCache
)

Flexible constructor allowing to pick the strategy and if caching should be used

Method Summary

Modifier and TypeMethod and Description
public <T> ObjectInstantiator<T>

Returns:

Instantiator dedicated to the class
getInstantiatorOf
(Class<T>
Class to instantiate
clazz
)

Implements org.objenesis.Objenesis.getInstantiatorOf.

Will pick the best instantiator for the provided class.
public <T> T

Returns:

New instance of clazz
newInstance
(Class<T>
Class to instantiate
clazz
)

Implements org.objenesis.Objenesis.newInstance.

Will create a new object without any constructor being called
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cacheback to summary
protected ConcurrentHashMap<String, ObjectInstantiator<?>> cache

Strategy cache. Key = Class, Value = InstantiatorStrategy

strategyback to summary
protected final InstantiatorStrategy strategy

Strategy used by this Objenesis implementation to create classes

Constructor Detail

ObjenesisBaseback to summary
public ObjenesisBase(InstantiatorStrategy strategy)

Constructor allowing to pick a strategy and using cache

Parameters
strategy:InstantiatorStrategy

Strategy to use

ObjenesisBaseback to summary
public ObjenesisBase(InstantiatorStrategy strategy, boolean useCache)

Flexible constructor allowing to pick the strategy and if caching should be used

Parameters
strategy:InstantiatorStrategy

Strategy to use

useCache:boolean

If ObjectInstantiators should be cached

Method Detail

getInstantiatorOfback to summary
public <T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz)

Implements org.objenesis.Objenesis.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 calling newInstance(Class).

Parameters
<T>

Doc from org.objenesis.Objenesis.getInstantiatorOf. Type to instantiate

clazz:Class<T>

Class to instantiate

Returns:ObjectInstantiator<T>

Instantiator dedicated to the class

Annotations
@SuppressWarnings:unchecked
newInstanceback to summary
public <T> T newInstance(Class<T> clazz)

Implements org.objenesis.Objenesis.newInstance.

Will create a new object without any constructor being called

Parameters
<T>

Doc from org.objenesis.Objenesis.newInstance. Type instantiated

clazz:Class<T>

Class to instantiate

Returns:T

New instance of clazz

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override