怎么出现这样的结果?

nemo天地 2008-04-30 10:49:35
public class ReflectTest {
public static void main(String[] args) {
Class c = null;
try {
c = Class.forName(args[0]);
System.out.println("package " + c.getPackage().getName());// 获取包名
System.out.print(Modifier.toString(c.getModifiers()));// 获取类的修饰符
System.out.print(" class " + c.getSimpleName());// 获取类名
System.out.print(" extends " + c.getSuperclass().getSimpleName());// 获取父类名
Class[] inters = c.getInterfaces();
if (inters.length > 0) {
System.out.print(" implements ");
for (int i = 0; i < inters.length; i++) {//
System.out.print(inters[i].getSimpleName());
if (i < inters.length - 1) {
System.out.print(",");
}
}
}
System.out.println("{");
System.out.println("\n\t// all fields:");
PrintFields(c);
System.out.println("\n\t// all Constructors:");
printConstructors(c);
System.out.println("\n\t// all Methods:");
printMethods(c);
System.out.println("}");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

public static void PrintFields(Class c) {// 获取属性
Field[] fields = c.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
System.out.print("\t" + Modifier.toString(f.getModifiers()));// getModifiers()得到属性修饰符
System.out.print(" " + f.getType().getSimpleName());// getType()得到属性数据类型
System.out.println(" " + f.getName() + ";");// getName()得到属性名
}
}

public static void printConstructors(Class c) {// 获取构造方法
Constructor[] cons = c.getDeclaredConstructors();
for (int i = 0; i < cons.length; i++) {
Constructor con = cons[i];
System.out.print("\t" + Modifier.toString(con.getModifiers()));// 构造方法的修饰符
System.out.print(" " + c.getSimpleName() + "(");// 构造方法的方法名
Class[] allPara = con.getParameterTypes();
for (int j = 0; j < allPara.length; j++) {
System.out.print(allPara[j].getSimpleName() + " args" + j);// 参数(形参)类型
if (j < allPara.length - 1) {
System.out.print(",");
}
}
System.out.println(")");
Class[] allException = con.getExceptionTypes();//异常
if (allException.length > 0) {
System.out.print(" throws ");
for (int k = 0; k < allException.length; k++) {
System.out.print(allException[k].getSimpleName());
if (k < allException.length - 1) {
System.out.print(",");
}
}
}

}
System.out.println("{ ...... }");
}

public static void printMethods(Class c) {// 获取方法
Method[] allMethods = c.getDeclaredMethods();
for (int i = 0; i < allMethods.length; i++) {
Method m = allMethods[i];
System.out.print("\t" + Modifier.toString(m.getModifiers()));// 修饰符
System.out.print(" " + m.getReturnType());// 返回值类型
System.out.print(" " + m.getName() + "(");// 方法名
Class[] allPara = m.getParameterTypes();
for (int j = 0; j < allPara.length; j++) {
System.out.print(allPara[j].getSimpleName() + " args" + j);// 参数(形参)类型
if (j < allPara.length - 1) {
System.out.print(",");
}
}
System.out.print(")");
Class[] allException = m.getExceptionTypes();//异常
if (allException.length > 0) {
System.out.print(" throws ");
for (int k = 0; k < allException.length; k++) {
System.out.print(allException[k].getSimpleName());
if (k < allException.length - 1) {
System.out.print(",");
}
}
}
System.out.print("{");
System.out.print("......");
System.out.print("}");
}
}
}
这个程序哪里出错了,运行结果怎么出现UnsupportedEncodingException,什么意思啊
...全文
56 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
AwL_1124 2008-05-02
  • 打赏
  • 举报
回复
感觉Eclipse的编码很麻烦···
nemo天地 2008-05-01
  • 打赏
  • 举报
回复
我用的就是eclipse;可是就是出错,不知道哪里错了?
Shine_Panda 2008-05-01
  • 打赏
  • 举报
回复
调一下编码试试..........
loaferwang 2008-05-01
  • 打赏
  • 举报
回复
也许就是楼上所说,你的工具不对,JBuilder,Eclipse ,甚至txt文件都行,你看看!
zero1111 2008-04-30
  • 打赏
  • 举报
回复
你用的什么编辑工具? 应该是不认你备注的中文.
把中文去了就通过了.

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧