红色标记的地方为何要用String强转???
package zhangli1;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class ReflectDemo {
/**
* @param args
* @throws ClassNotFoundException
* @throws NoSuchMethodException
* @throws SecurityException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws IllegalArgumentException
*/
public static void main(String[] args) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
// TODO Auto-generated method stub
String str1="abcdef";
Class c1=str1.getClass();
Class c2=String.class;
Class c3=Class.forName("java.lang.String");
System.out.println(c1==c2);
System.out.println(c2==c3);
Constructor con=String.class.getConstructor(StringBuffer.class);
String str2= (String)con.newInstance(new StringBuffer("sljfielei"));
System.out.println(str2.charAt(7));
}
}
|