Java Reflection Constructor Invoke invokePrivateConstructor(Class classType)

Here you can find the source of invokePrivateConstructor(Class classType)

Description

invoke Private Constructor

License

Open Source License

Declaration

public static <E> void invokePrivateConstructor(Class<E> classType) throws Exception 

Method Source Code

//package com.java2s;
/*/* w ww  .j a  va 2  s .  co m*/
 * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.lang.reflect.Constructor;

public class Main {
    public static <E> void invokePrivateConstructor(Class<E> classType) throws Exception {
        Constructor<E> constructor = classType.getDeclaredConstructor();
        constructor.setAccessible(true);
        constructor.newInstance();
    }
}

Related

  1. invokeConstructor(String className, Object... arguments)
  2. invokeConstructorOrFail(Constructor constructor, Object... args)
  3. invokeCtor(Constructor ctor, String str)
  4. invokeExactConstructor(Class klass, Object arg)
  5. invokePrivateConstructor(Class clazz)
  6. invokePrivateConstructor(Class clazz)
  7. invokeReflectConstruct(String className, Object[] parameter, Class[] args)