马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 565123 于 2013-10-10 13:28 编辑 package test;
import java.lang.reflect.Field;
public class Test {
public static void main(String[] args) {
changeString("123", "456");
System.out.println("123");
}
private static void changeString(String s, String sample)
throws NullPointerException {
changeString(s, sample.toCharArray());
}
private static void changeString(String str, char[] chs)
throws NullPointerException {
if (str == null)
throw new NullPointerException("s cannot be null.");
Field field = null;
try {
field = String.class.getDeclaredField("value");
field.setAccessible(true);
field.set(str, chs);
} catch (Exception e) {
e.printStackTrace();
}
}
}
测试看看鱼油们的水平!!
是不是运行起来和预期的结果不一样! |