zoukankan      html  css  js  c++  java
  • 如何通过反射将字符串转换为类

    package org.entity;
    /**
     * 本案例演示如何通过反射将字符串转换为类
     * */
    public class Test {
      
    	public static void main(String[] args) {
    		String user = "org.entity.User";//字符串是该类的全限定名
    			try {
    				Class clzz = Class.forName(user);
    				Object classObj=clzz.newInstance();//将class类转换为对象
    				System.out.println(classObj);//
    			} catch (ClassNotFoundException e) {
    				e.printStackTrace();
    			} catch (InstantiationException e) {
    				e.printStackTrace();
    			} catch (IllegalAccessException e) {
    				e.printStackTrace();
    			}
    		
    	}
    
    }
    

  • 相关阅读:
    第十三周
    意见评论
    第十二周
    冲刺10
    冲刺9
    冲刺8
    团队冲刺第二十二天-KeepRunningAPP
    找水王
    第十四周总结
    搜狗输入法评价
  • 原文地址:https://www.cnblogs.com/a1111/p/6540272.html
Copyright © 2011-2022 走看看