我正在尝试使用反射打印构造函数名称,但是它跳过了用于打印循环名称的循环。
package reflection.com;
import java.lang.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
abstract interface FirstInterface {
void showFirstInterface();
}
abstract interface SecondInterface {
void showSecondInterface();
}
abstract interface ThirdInterface {
void showThirdinterface();
}
class SuperClass implements FirstInterface {
int x, y, z;
SuperClass() {
System.out.println("Super Class Constructor...");
}
public void showFirstInterface() {
System.out.println("In class Super Class....");
}
}
public class SubClass extends SuperClass implements SecondInterface, ThirdInterface {
int a, b, c;
SubClass() {
}
SubClass(int a, int b, int c) {
}
public void showSecondInterface() {
System.out.println("In class Sub Class implementing Second Interface...");
}
public void showThirdinterface() {
System.out.println("In class Sub Class implementing Third Interface...");
}
}
class ReflectionTest {
public static void main(String[] args) {
Class class1 = SubClass.class;
int modifier = class1.getModifiers();
Class superClass = class1.getSuperclass();
Class[] interfaces = class1.getInterfaces();
Constructor[] constructor = class1.getConstructors();
Method[] method = class1.getMethods();
Field[] field = class1.getFields();
System.out.println("Fully Qualified Class Name..." + class1.getName());
System.out.println("Class Name..." + class1.getSimpleName());
System.out.println("Class Modifier...." + Modifier.isPublic(modifier));
System.out.println("Class Super Class....." + superClass.getName());
System.out.println("Following are the interfaces.....");
for (int i = 0; i < interfaces.length; i++) {
System.out.println(interfaces[i].getName());
}
System.out.println("Following are the Constructor.....");
for (int i = 0; i < constructor.length; i++) {
System.out.println(constructor[i].getName());
}
System.out.println("Following are the Fields.....");
for (int i = 0; i < field.length; i++) {
System.out.println(field[i].getName());
}
System.out.println("Following are the Methods.....");
for (int i = 0; i < method.length; i++) {
System.out.println(method[i].getName());
}
for (Method method1 : method) {
System.out.println(method1.getName());
}
}
}
我试图调试应用程序,但没有使用它不进入 for 循环本身。
谁能帮我这个?