📄 requestor.java
字号:
/* * 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]); // get an array of Provider field information Field field[] = provClass.getDeclaredFields(); for (int x=0; x<field.length; x++) System.out.println("Field " + x + " = " + field[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, methods, and fields 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -