???????
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
public class Test {
public static void main(String[] args){
ResourceBundle bundle = ResourceBundle.getBundle("user");
Class c1 = null;
try {
c1 = Class.forName(bundle.getString("classValue"));
StringBuffer buffer = new StringBuffer();
Class[] classes = c1.getInterfaces();
for (Class c : classes){
buffer.append(c.getSimpleName());
buffer.append(", ");
}
if (classes.length > 0){
buffer.deleteCharAt(buffer.length() - 1);
buffer.deleteCharAt(buffer.length() - 1);
}
System.out.println(Modifier.toString(c1.getModifiers())
+ " class " + c1.getSimpleName()
+ " extends " + c1.getSuperclass().getSimpleName()
+ " implements " + buffer + " {");
Field[] field = c1.getDeclaredFields();
for (Field f : field){
System.out.println("\t" + Modifier.toString(f.getModifiers())
+ " " + f.getType().getSimpleName()
+ " " + f.getName());
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println();
Constructor[] constructor = c1.getConstructors();
for (Constructor c : constructor){
StringBuffer buffer1 = new StringBuffer();
Class[] parameter = c.getParameterTypes();
for (Class p : parameter) {
buffer1.append(p.getSimpleName());
buffer1.append(", ");
}
String str = null;
if (parameter.length > 0){
str = buffer1.substring(0, buffer1.length() - 2);
}
System.out.println( "\t" + Modifier.toString(c.getModifiers())
+ " " + c1.getSimpleName() + "(" + str + ")");
}
System.out.println();
Method[] method = c1.getDeclaredMethods();
for (Method m : method){
StringBuffer buffer2 = new StringBuffer();
Class[] parameter = m.getParameterTypes();
for (Class c : parameter){
buffer2.append(c.getSimpleName());
buffer2.append(", ");
}
String str = null;
if (parameter.length > 0){
str = buffer2.substring(0, buffer2.length() - 2);
}
System.out.println("\t" + Modifier.toString(m.getModifiers())
+ " " + m.getReturnType().getSimpleName()
+ " " + m.getName() + "(" + str + ")");
}
System.out.println("}");
}
}
|