- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- String str = "abcd";
- Class<?> clazz = Class.forName("java.lang.String");
- Constructor<?> constructor = clazz.getConstructor(StringBuilder.class);
- str = (String) constructor.newInstance(new StringBuilder("abc"));
- System.out.println(str.charAt(1));
- ReflectPoint pt = new ReflectPoint(3, 5);
- String variableName = "y";
- Field field = getField(pt, variableName);
- System.out.println(field.get(pt));
- char oldChar = 'b';
- char newChar = 'a';
- changeStringVal(pt, oldChar, newChar);
- System.out.println(pt);
- Method methodCharAt = String.class.getMethod("charAt", int.class);
- System.out.println(methodCharAt.invoke(str, 2));
- System.out.println(methodCharAt.invoke(str, new Object[] { 1 }));
- String startingClassName = args[0];
- Method mainMethod = Class.forName(startingClassName).getMethod("main",String[].class);
- mainMethod.invoke(null, (Object) new String[] { "aaa", "bbb", "ccc" });
- int[] a1 = new int[3];
- int[][] a2 = new int[3][];
- String[] a3 = new String[3];
- System.out.println(a1.getClass() ==a2.getClass());
- System.out.println(a1.getClass()==a3.getClass());
- }
复制代码 |