listing28.1.java

来自「java 完全探索的随书源码」· Java 代码 · 共 42 行

JAVA
42
字号
/** Requestor*/import java.lang.reflect.*;public class Requestor {  public void requestConstuctors() {    try {      // load the Provider class and use Reflection      // to get an array of constructor information      Constructor con[]= Class.forName("Provider").getDeclaredConstructors();      for (int x=0; x<con.length; x++)        System.out.println("Constructor " + x + " = " + con[x]);    }    catch (ClassNotFoundException ce) {      // Class.forName was unable to load Provider.class      System.out.println("Could not locate class");    }    catch (SecurityException se) {      // Reflection permission was not granted      System.out.println("Not allowed to get class info");    }  }  public static void main(String args[]) {    // construct a Requestor and ask it for the    // constructors declared by Provider    Requestor req = new Requestor();    req.requestConstuctors();  }}/* *  Provider*/class Provider {  public Provider(String s) {  }  private Provider(int i) {  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?