import java.lang.reflect.Constructor;
public class ReflectTest {
public static void main(String[] args)throws Exception {
Constructor constructor1 = String.class.getConstructor(StringBuffer.class);
String str2 = (String)constructor1.newInstance(new StringBuffer("abc"));
System.out.println(constructor1.toString());
}
}
一开始从传入参数就知道是StringBuffer类的,那为什么还要用constructor方法特地绕一圈回来在求StringBuffer呢?
还有constructor的实际应用? |
|