日期:2014-05-20 浏览次数:20787 次
public class Test {
public static void main(String[] args) {
Integer num = new Integer(1);
System.out.println(num);
fun(num);
System.out.println(num);
}
public static void fun(Integer num){
num.valueOf(3);
}
import java.lang.reflect.Field;
public class Test2 {
public static void main(String[] args) {
Integer num = new Integer(1);
System.out.println(num);
fun(num);
System.out.println(num);
}
public static void fun(Integer num) {
Class clazz = num.getClass();
try {
Field field = clazz.getDeclaredField("value");
field.setAccessible(true);
field.set(num, 3);
field.setAccessible(false);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}