< prev index next >

src/java.base/share/classes/java/lang/reflect/Constructor.java

Print this page




 426      *              conversion for primitive arguments fails; or if,
 427      *              after possible unwrapping, a parameter value
 428      *              cannot be converted to the corresponding formal
 429      *              parameter type by a method invocation conversion; if
 430      *              this constructor pertains to an enum type.
 431      * @exception InstantiationException    if the class that declares the
 432      *              underlying constructor represents an abstract class.
 433      * @exception InvocationTargetException if the underlying constructor
 434      *              throws an exception.
 435      * @exception ExceptionInInitializerError if the initialization provoked
 436      *              by this method fails.
 437      */
 438     @CallerSensitive
 439     @ForceInline // to ensure Reflection.getCallerClass optimization
 440     public T newInstance(Object ... initargs)
 441         throws InstantiationException, IllegalAccessException,
 442                IllegalArgumentException, InvocationTargetException
 443     {
 444         if (!override) {
 445             Class<?> caller = Reflection.getCallerClass();
 446             checkAccess(caller, clazz, null, modifiers);
 447         }
 448         if ((clazz.getModifiers() & Modifier.ENUM) != 0)
 449             throw new IllegalArgumentException("Cannot reflectively create enum objects");
 450         ConstructorAccessor ca = constructorAccessor;   // read volatile
 451         if (ca == null) {
 452             ca = acquireConstructorAccessor();
 453         }
 454         @SuppressWarnings("unchecked")
 455         T inst = (T) ca.newInstance(initargs);
 456         return inst;
 457     }
 458 
 459     /**
 460      * {@inheritDoc}
 461      * @since 1.5
 462      */
 463     @Override
 464     public boolean isVarArgs() {
 465         return super.isVarArgs();
 466     }




 426      *              conversion for primitive arguments fails; or if,
 427      *              after possible unwrapping, a parameter value
 428      *              cannot be converted to the corresponding formal
 429      *              parameter type by a method invocation conversion; if
 430      *              this constructor pertains to an enum type.
 431      * @exception InstantiationException    if the class that declares the
 432      *              underlying constructor represents an abstract class.
 433      * @exception InvocationTargetException if the underlying constructor
 434      *              throws an exception.
 435      * @exception ExceptionInInitializerError if the initialization provoked
 436      *              by this method fails.
 437      */
 438     @CallerSensitive
 439     @ForceInline // to ensure Reflection.getCallerClass optimization
 440     public T newInstance(Object ... initargs)
 441         throws InstantiationException, IllegalAccessException,
 442                IllegalArgumentException, InvocationTargetException
 443     {
 444         if (!override) {
 445             Class<?> caller = Reflection.getCallerClass();
 446             checkAccess(caller, clazz, clazz, modifiers);
 447         }
 448         if ((clazz.getModifiers() & Modifier.ENUM) != 0)
 449             throw new IllegalArgumentException("Cannot reflectively create enum objects");
 450         ConstructorAccessor ca = constructorAccessor;   // read volatile
 451         if (ca == null) {
 452             ca = acquireConstructorAccessor();
 453         }
 454         @SuppressWarnings("unchecked")
 455         T inst = (T) ca.newInstance(initargs);
 456         return inst;
 457     }
 458 
 459     /**
 460      * {@inheritDoc}
 461      * @since 1.5
 462      */
 463     @Override
 464     public boolean isVarArgs() {
 465         return super.isVarArgs();
 466     }


< prev index next >