package reflection06;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Erzeugung eines Objektes.
 * 
 * @author  Ralf Kunze (rkunze@uos.de), Institut fuer Informatik, Universitaet Osnabrueck
 * @date 02.06.2007
 */
public class InstanciateTest {

    public static void main(String[] args) {
        Class<Integer> integerClass = Integer.class;
        
        Integer i = null;
        
        try {
            Constructor<Integer> integerConstructor = integerClass.getConstructor(Integer.TYPE);
            i = integerConstructor.newInstance(42);
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            System.err.println("Konstruktor nicht gefunden");
        } catch (IllegalArgumentException e) {
            System.err.println("Konstruktorargumente nicht erlaubt");
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        System.out.println(i.getClass() + "  " + i);
    }

}
