package com.hello.ds;
public class Alpha {
public static void main(String[] args) {
System.out.println("return value of getValue(): " + getValue());
}
public static int getValue() {
int i = 1;
try {
i = 4;
return i;
} finally{
i++;
// return i;
}
}
public class Alpha {
public static void main(String[] args) {
System.out.println("return value of getValue(): " + getValue());
}
public static int getValue() {
int i = 1;
try {
i = 4;
return i;
} finally{
i++;
// return i;
}
}
}
1:(try里有return finally里没有return ) return value of getValue(): 4
2:(如果try里没有return finally里有return) return value of getValue(): 5
3 (try和finally里都有return) finally里的return~会覆写try块里要return的值 return value of getValue(): 5