1.首先写一基本的Java类User
package com.che.test;public class User { private String name;}2.写一应用类Apppackage com.che.test;import java.lang.reflect.Array;import java.lang.reflect.Field;import java.lang.reflect.Method;public class App { public static void main(String[] args) { String objName="com.che.test.User"; try{ Class cs=Class.forName(objName); Object obj=cs.newInstance(); Field name=cs.getDeclaredField("name"); name.setAccessible(true); System.out.println(name.get(obj)); name.set(obj, "che"); System.out.println(name.get(obj)); name.setAccessible(false); }catch(Exception e){ e.printStackTrace(); } }}