newInstance method (format 3)

Description

Executes the constructor indicated by the parameter cons in the parameter args, and then directly creates the instance in the Explicit memory block indicated by the object. Only the instances of the class specified in the parameter are created in the Explicit memory block. The objects created through initialization by the constructor of the instances of class specified in the parameter are created in the Java heap.

Format

public Object newInstance(java.lang.reflect.Constructor cons,  Object... args);

Parameters

cons:
This parameter specifies the constructor of the array instance to be created directly.
args:
This is a parameter that is passed to the constructor.

Exceptions

NullPointerException:
The value of either one or both the parameters cons and args is null.
ExceptionInInitializerError:
An attempt to initialize the class with the constructor indicated by the parameter cons has failed.
InstantiationException:
The constructor indicated by the parameter cons is an abstract class.
IllegalArgumentException:
The parameter of the constructor indicated by the parameter cons does not match the parameter args.
InvocationTargetException:
An exception occurred during the execution of the constructor indicated by the parameter cons or parameter args.
InaccessibleMemoryAreaException:
This functionality is not supported.

Return value

This method returns the reference to the instances created in the Explicit memory block indicated by the method.

If it is judged that processing cannot be executed by performing the common error check, invoke parameter cons of java.lang.reflect.Constructor.newInstance(Object... initargs) as this object, parameter args as a parameter, and return that result. For details on common error check, see 10.6 Error check (common error check) of the process that controls the Explicit memory block .

Caution

We recommend that you add the constructor of a public class in the parameter cons.