Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.*;

public class Main {
    public static <T extends Object> T newInstance(Class<T> cl, Object... args) throws NoSuchMethodException,
            IllegalAccessException, InvocationTargetException, InstantiationException {
        Constructor<T> constructor = cl.getDeclaredConstructor(new Class[0]);
        boolean accessible = constructor.isAccessible();
        constructor.setAccessible(true);
        T t = constructor.newInstance(args);
        constructor.setAccessible(accessible);
        return t;
    }
}