import java.lang.reflect.*;
public class exam_22 {
public static void main(String[] args) throws ClassNotFoundException {
if(args.length<1){
System.out.println("请输入类的名称!");
return;
}
__________ c = Class.forName(args[0]);
print_class(c);
}
public static void print_class(Class c)
{
if (c.isInterface()) {
System.out.print(Modifier.toString(c.getModifiers()) + " " +
typename(c));
}
else if (c.getSuperclass() != null) {
System.out.print(Modifier.toString(c.getModifiers()) + " class " +
typename(c) +
" extends " + typename(c.getSuperclass()));
}
else {
System.out.print(Modifier.toString(c.getModifiers()) + " class " +
typename(c));
}
Class[] interfaces = c.getInterfaces();
if ((interfaces != null)&& (interfaces.length > 0)) {
if (c.isInterface()) System.out.print(" extends ");
else System.out.print(" implements ");
for(int i = 0; i < interfaces.length; i++) {
if (i > 0) System.out.print(", ");
System.out.print(typename(interfaces[i]));
}
}
System.out.println(" {");
System.out.println(" // Constructors");
Constructor[] constructors = c.getDeclaredConstructors();
for(int i = 0; i < constructors.length; i++)
print_method_or_constructor(constructors[i]);
System.out.println(" // Fields");
Field[] fields = c.getDeclaredFields();
for(int i = 0; i < fields.length; i++)
print_field(fields[i]);
System.out.println(" // Methods");
__________ = c.getDeclaredMethods();
for(int i = 0; i < methods.length; i++)
print_method_or_constructor(methods[i]);
System.out.println("}");
}
public static String typename(Class t) {
String brackets = "";
while(t.isArray()) {
brackets += "[]";
t = t.getComponentType();
}
String name = t.getName();
int pos = name.lastIndexOf('.');
if (pos != -1) name = name.substring(pos+1);
return name + brackets;
}
public static String modifiers(int m) {
if (m == 0) return "";
else return Modifier.toString(m) + " ";
}
public static void print_field(Field f) {
System.out.println(" " + modifiers(f.getModifiers()) +
typename(f.getType()) + " " + f.getName() + ";");
}
public static void print_method_or_constructor(Member member) {
Class returntype=null, parameters[], exceptions[];
if (member instanceof Method) {
Method m = (Method) member;
returntype = m.getReturnType();
parameters = m.getParameterTypes();
exceptions = m.getExceptionTypes();
System.out.print(" " + modifiers(member.getModifiers()) +
typename(returntype) + " " + member.getName() +
"(");
} else {
Constructor c = (Constructor) member;
parameters = c.getParameterTypes();
exceptions = c.getExceptionTypes();
System.out.print(" " + modifiers(member.getModifiers()) +
typename(c.getDeclaringClass()) + "(");
}
for(int i = 0; i < parameters.length; i++) {
if (i > 0) System.out.print(", ");
System.out.print(typename(parameters[i]));
}
System.out.print(")");
if (exceptions.length > 0) System.out.print(" throws ");
for(int i = 0; i < exceptions.length; i++) {
if (i > 0) System.out.print(", ");
System.out.print(typename(exceptions[i]));
}
System.out.println(";");
}
}
二级JAVA南开100题1
需积分: 0 134 浏览量
2008-12-19
23:24:46
上传
评论 1
收藏 89KB RAR 举报
muguangkui
- 粉丝: 14
- 资源: 319
最新资源
- tesseract安装包
- 1_32陀螺仪舵机.zip
- HITJ0302MP-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- XILINXFPGA源码PCIExpress标准概述
- HITJ0204MP-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- XILINXFPGA源码PCIExpressIP核应用参考设计
- XILINXFPGA源码LCD12864在Spartan-3E实现代码
- XILINXFPGA源码LCDIPCORE
- G6402-VB一款SOT23封装P-Channel场效应MOS管
- XILINXFPGA源码IPcamera的开源系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0