public class J { public Integer method(Integer x) { Integer val = x; try { return val; } finally { val = x + x; } } public static void main(String[] args) { J littleFuzzy = new J(); System.out.println(littleFuzzy.method(new Integer(10))); } }
它将返回“10”.
现在我只是将Return类型的整数替换为StringBuilder,而Output被更改.
public class I { public StringBuilder method(StringBuilder x) { StringBuilder val = x; try { return val; } finally { val = x.append("aaa"); } } public static void main(String[] args) { I littleFuzzy = new I(); System.out.println(littleFuzzy.method(new StringBuilder("abc"))); } }
OutPut是“abcaaa”
所以,任何人都可以详细解释一下.
有什么区别.?