package Reflect_Demo;
import java.io.FileReader;
import java.lang.reflect.Constructor;
import java.text.DateFormat;
import java.util.Date;
public class Reflect_method {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException {
String name="daxiong";
int age=18;
String className="Reflect_Demo.Person";
Class clazz=Class.forName(className);
Constructor constructor=clazz.getConstructor(String.class,int.class);
}
}
这边getConstructor下面划红线报错:The method getConstructor(Class[]) in the type Class is not applicable for the arguments (Class<T>, Class<T>);
然后我把clazz.getConstructor(String.class,int.class);改为clazz.getConstructor(new Class[]{String.class,int.class})就编译通过了,但是getConstructor传递的不是可变数组吗
------解决思路----------------------
getConstruct()参数是个数组,你把你要传的参数放到数组中就行了,你的jdk版本和老师的应该是不一样的,
------解决思路----------------------
jdk版本问题吗?