Top Description Fields Constructors Methods
org.apache.commons.collections4.functors

public Class InstantiateFactory<T>

extends Object
implements Factory<T>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.Factory
Imports
java.lang.reflect.Constructor, .InvocationTargetException, org.apache.commons.collections4.Factory, .FunctorException

Factory implementation that creates a new object instance by reflection.

Warning

from v4.1 onwards this class will not be serializable anymore in order to prevent potential remote code execution exploits. Please refer to COLLECTIONS-580 for more details.

Since
3.0

Field Summary

Modifier and TypeField and Description
private final Object[]
iArgs

The constructor arguments

private final Class<T>
iClassToInstantiate

The class to create

private transient Constructor<T>
iConstructor

The constructor

private final Class<?>[]
iParamTypes

The constructor parameter types

Constructor Summary

AccessConstructor and Description
public
InstantiateFactory(final Class<T>
the class to instantiate
classToInstantiate
)

Constructor that performs no validation.

public
InstantiateFactory(final Class<T>
the class to instantiate
classToInstantiate
,
final Class<?>[]
the constructor parameter types, cloned
paramTypes
,
final Object[]
the constructor arguments, cloned
args
)

Constructor that performs no validation.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the new object
create
()

Implements org.apache.commons.collections4.Factory.create.

Creates an object using the stored constructor.
private void
findConstructor()

Find the Constructor for the class specified.

public static <
the type the factory creates
T
>
Factory<T>

Returns:

a new instantiate factory
instantiateFactory
(final Class<T>
the class to instantiate, not null
classToInstantiate
,
final Class<?>[]
the constructor parameter types, cloned
paramTypes
,
final Object[]
the constructor arguments, cloned
args
)

Factory method that performs validation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iArgsback to summary
private final Object[] iArgs

The constructor arguments

iClassToInstantiateback to summary
private final Class<T> iClassToInstantiate

The class to create

iConstructorback to summary
private transient Constructor<T> iConstructor

The constructor

iParamTypesback to summary
private final Class<?>[] iParamTypes

The constructor parameter types

Constructor Detail

InstantiateFactoryback to summary
public InstantiateFactory(final Class<T> classToInstantiate)

Constructor that performs no validation. Use instantiateFactory if you want that.

Parameters
classToInstantiate:Class<T>

the class to instantiate

InstantiateFactoryback to summary
public InstantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args)

Constructor that performs no validation. Use instantiateFactory if you want that.

Parameters
classToInstantiate:Class<T>

the class to instantiate

paramTypes:Class<?>[]

the constructor parameter types, cloned

args:Object[]

the constructor arguments, cloned

Method Detail

createback to summary
public T create()

Implements org.apache.commons.collections4.Factory.create.

Creates an object using the stored constructor.

Returns:T

the new object

Annotations
@Override
findConstructorback to summary
private void findConstructor()

Find the Constructor for the class specified.

instantiateFactoryback to summary
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args)

Factory method that performs validation.

Parameters
<T>
the type the factory creates
classToInstantiate:Class<T>

the class to instantiate, not null

paramTypes:Class<?>[]

the constructor parameter types, cloned

args:Object[]

the constructor arguments, cloned

Returns:Factory<T>

a new instantiate factory

Exceptions
NullPointerException:
if classToInstantiate is null
IllegalArgumentException:
if paramTypes does not match args