public class Demo6 {
public static void main(String[] args) {
Person p = haha();
System.out.println(p.age);
}
public static Person haha(){
Person p = new Person();
try{
p.age = 18;
return p;
}catch(Exception e){
return null;
}finally {
p.age = 28;
}
}
static class Person{
int age;
}
}
这个代码是备份的内存地址,内存地址没变,年龄换成28,所以结果为28
package com.java.demo1;
public class Demo7 {
public static void main(String[] args) {
int a = haha();
System.out.println(a);
}
public static int haha(){
int a = 10;
try{
return a;
}catch(Exception e){
}finally {
a = 20;
}
return 0;
}
static class Person{
int age;
}
}