listing28.6.java

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

JAVA
65
字号
/* * 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      Class provClass = Class.forName("Provider");      Constructor con[] = provClass.getDeclaredConstructors();      for (int x=0; x<con.length; x++)        System.out.println("Constructor " + x + " = " + con[x]);      // get an array of Provider method information      Method meth[] = provClass.getDeclaredMethods();      for (int x=0; x<meth.length; x++)        System.out.println("Method " + x + " = " + meth[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 and methods declared by Provider    Requestor req = new Requestor();    req.requestConstuctors();  }}/* *  Provider */class Provider {  String attribute;  // construct with a String to assign to the attribute  public Provider(String s) {    attribute = s;  }  // construct with an int to assign to the attribute  private Provider(int i) {    attribute = String.valueOf(i);  }  // set the attribute String  public void setAttribute(String attribute) {    this.attribute = attribute;  }  // get the attribute String  public String getAttribute() {    return attribute;  }}

⌨️ 快捷键说明

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