必须知道,别滥用-finally
public class Test { public static int testInt() { int x = 0; try { x = 1; System.out.println("x=1"); return x; } finally { x = 2; System.out.println("x=2"); } } public static Ref testRef() { Ref ref = new Ref(); try { ref.x = 1; System.out.println("x=1"); return ref; } finally { ref.x = 2; System.out.println("x=2"); } } public static void main(String[] args) { System.out.println("x=? " + testInt()); System.out.println("x=? " + testRef()); } private static class Ref { private int x; public String toString(){ return String.valueOf(x); } }} 1 楼 trydofor 2011-04-22 后续跟踪: