集册 Java实例教程 类新实例

类新实例

欢马劈雪     最近更新时间:2020-01-02 10:19:05

444
类新实例

/*
时代Java公众号 - N o w J a  v a . c o m
*/

//package com.nowjava;


import java.lang.reflect.Constructor;

import java.lang.reflect.InvocationTargetException;


import java.util.Map;


public class Main {

    public static void main(String[] argv) throws Exception {

        Class theClass = String.class;

        System.out.println(newInstance(theClass));

    }


    private static Map primitiveClassWrapperMap;


    public static Object newInstance(Class theClass)

            throws InstantiationException, IllegalAccessException {/*时   代    Java - nowjava.com*/

        if (null != primitiveClassWrapperMap.get(theClass)) {

            theClass = (Class) primitiveClassWrapperMap.get(theClass);

        }

        return theClass.newInstance();

    }


    public static Object newInstance(Class theClass, String param)

            throws InstantiationException, IllegalAccessException,

            SecurityException, NoSuchMethodException,

            IllegalArgumentException, InvocationTargetException {

        if (null != primitiveClassWrapperMap.get(theClass)) {

            theClass = (Class) primitiveClassWrapperMap.get(theClas
展开阅读全文