//反射,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(); }