newInstance method (format 1)

Description

Directly creates the instances of the class indicated by the parameter type 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 the initialization by the constructor of the instances of the class specified in the parameter are created in the Java heap. type is same as Class.newInstance() for this object, however some part is different.

Format

public Object newInstance(Class type);

Parameters

type:
This is the class of the array instance to be created directly.

Exceptions

NullPointerException:
Either the parameter type or the class indicated by the parameter type is null.
SecurityException:
This exception is thrown when SecurityManager exists, and when any of the following conditions hold true:
  • The invocation of s.checkMemberAccess(type, Member.PUBLIC) does not allow access to this constructor.
  • The class loader at the calling side is different.
  • The invocation of the class loader higher than the current class loader and also the invocation of s.checkPackageAccess() do not allow access to the package of this class.
NoSuchMethodException:
No constructor, without a public parameter, exists in either the parameter type or the class indicated by the parameter type.
ExceptionInInitializerError:
An attempt to initialize the parameter type or the class indicated by the parameter type has failed.
InstantiationException:
The parameter type or the class indicated by the parameter type is either an abstract class or an interface.
InvocationTargetException:
An exception occurred during the execution of the parameter type or the constructor of the class indicated by the parameter type.
IllegalAccessException:
The class or its nullary constructor cannot be accessed.
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 object.

If it is judged that processing cannot be executed by performing the common error check, invoke the Class.newInstance() method by considering the parameter type as a receiver, 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 a public class in the parameter type.