- package ConstructorDemo;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.InvocationTargetException;
- public class ConstructorTest {
- public static void main(String[] args)
- throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
- Constructor con = String.class.getConstructor(char[].class);
- char [] c = {'a','b','c'};
- String str = (String)con.newInstance(c);
- System.out.println(str);
- }
- }
复制代码
首先,上边的代码是正确的,我想问的是,你看啊,那个char [] c = {'a','b','c'};对吧?
如果,你把String str = (String)con.newInstance(c);中的c换成{'a','b','c'}为什么就不对了? |
|