本帖最后由 王宝龙 于 2012-10-4 21:33 编辑
这个代码在Eclipse中有错误
大家帮忙看看我的代码哪里有问题
提示是:23行Constructor constructor1 = String.class.getConstructor(StringBuffer.class);
这个明明跟老师的是一模一样的啊!- public class ReflectTest
- {
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception
- {
- // TODO Auto-generated method stub
- String str1 = "abc";
- Class cls1 = str1.getClass();
- Class cls2 = String.class;
- Class cls3 = Class.forName("java.lang.String");
-
- System.out.println(cls1 == cls2);
- System.out.println(cls1 == cls3);
-
- System.out.println(cls1.isPrimitive());
- System.out.println(int.class.isPrimitive());
- System.out.println(int.class == Integer.class);
-
-
- Constructor constructor1 = String.class.getConstructor(StringBuffer.class);
-
- String str2 = (String)constructor1.newInstance(new StringBuffer("abc"));
-
- System.out.println(str2.charAt(2));
- }
- }
复制代码 |