1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package reflect;
import reflect.entity.Employee;
public class ClassSample { public static void main(String[] args) { try { Class emplyeeClass = Class.forName("reflect.entity.Employee"); System.out.println("已被加载"); Employee emp = (Employee) emplyeeClass.newInstance(); System.out.println(emp); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }
|