📄 listing28.1.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 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -