📄 reflect_demo7.java
字号:
import java.lang.reflect.*;
public class reflect_demo7{
public static void main(String args[])
{
try
{
Class cls = Class.forName("test");
Class partypes[] = new Class[2];
partypes[0] = String.class;
partypes[1] = Integer.TYPE;
Constructor meth = cls.getConstructor(partypes);
Object arglist[] = new Object[2];
arglist[0] = "hello the world";
arglist[1] = new Integer(47);
Object retobj = meth.newInstance(arglist);
System.out.println(retobj);
}
catch (Throwable e) {
System.err.println(e);
}
}
}
class test
{
private String name;
public int a;
public test(String name, int a)
{
this.name=name;
this.a=a;
}
public test()
{
}
public void show()
{
System.out.println("hello the test");
}
public int add(int a,int b)
{
return a+b;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -