//反射,CSharp中也有,关联联想起来,各语言的特点 JDK 14.02 geovindu try { // @SuppressWarnings("rawtypes") // Class testTypeClass = BookKind.class; @SuppressWarnings("rawtypes") Class DuTypeForName=Class.forName("Geovin.Model.BookKind"); System.out.println("类名称:"+DuTypeForName.getName()); System.out.println("继承:"+DuTypeForName.getInterfaces()); // testTypeForName.getFields()testTypeForName.getFields(); //私用属性,也是与数据库字段相应的名称,属性,在于后续代码的中变化,涂聚文 Geovin Du Field[] declaredFields = DuTypeForName.getDeclaredFields(); for (Field f : declaredFields) { System.out.println(f.getType()+","+f.getName()); } Method[] methods=DuTypeForName.getDeclaredMethods(); for(Method method:methods) { //打印修饰符public System.out.println("修饰符:"+Modifier.toString(method.getModifiers())); //打印返回值类型 System.out.println(" 返回值类型 "+method.getReturnType().getName()+" "); //打印方法名称 System.out.println("方法名称"+method+";"); } //@SuppressWarnings("rawtypes") //Class testTypeForName = Class.forName("Geovin.Model.BookKind"); } catch (ClassNotFoundException exception) { exception.printStackTrace(); }