📄 javapclass.java
字号:
import java.lang.reflect.*;
public class javapClass
{
public static void main(String[] args) throws Exception
{
Class test=Class.forName(args[0]);
System.out.println(test.getName());
System.out.println("{");
getDeclaredFields(test);
// getDeclaredConstructors(test);
// getDeclaredMethods(test);
constructors(test);
method(test);
System.out.println("}");
}
public static void getDeclaredConstructors(Class a){//构造
Constructor[] nowconstructor=a.getDeclaredConstructors();
for (int i=0;i<nowconstructor.length ;i++ ){
System.out.println(nowconstructor[i].toString());
}
System.out.println();
}
public static void getDeclaredFields(Class a){ //字段
Field[] nowfield=a.getDeclaredFields();
for (int i=0;i<nowfield.length ;i++ ){
nowfield[i].setAccessible(true);
System.out.print(Modifier.toString(nowfield[i].getModifiers())+" ");
Class newa=nowfield[i].getType();
System.out.print(newa.getName()+" ");
System.out.print(nowfield[i].getName()+";\n");
}
System.out.println();
}
public static void getDeclaredMethods(Class a){ //方法
Method[] nowmethod=a.getDeclaredMethods();
for (int i=0;i<nowmethod.length ;i++ ){
System.out.println(nowmethod[i].toString());
}
System.out.println();
}
public static void method(Class a){
Method[] nowmethod=a.getDeclaredMethods();
for (int i=0;i<nowmethod.length ;i++ ){
nowmethod[i].setAccessible(true);
System.out.print(Modifier.toString(nowmethod[i].getModifiers())+" ");
Class nowreturn=nowmethod[i].getReturnType();
System.out.print(nowreturn.getName()+" "+nowmethod[i].getName()+"(");
Class[] typename=nowmethod[i].getParameterTypes();
for (int j=0;j<typename.length ;j++ ){
if(j>0) System.out.print(",");
System.out.print(typename[j].getName());
}
System.out.println("){}");
}
System.out.println();
}
public static void constructors(Class a){
Constructor[] nowconstructor=a.getDeclaredConstructors();
for (int i=0;i<nowconstructor.length ;i++ ){
nowconstructor[i].setAccessible(true);
System.out.print(Modifier.toString(nowconstructor[i].getModifiers())+" ");
System.out.print(nowconstructor[i].getName()+"(");
Class[] typename=nowconstructor[i].getParameterTypes();
for (int j=0;j<typename.length ;j++ ){
if(j>0) System.out.print(",");
System.out.print(typename[j].getName());
}
System.out.println("){}");
}
System.out.println();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -