zoukankan      html  css  js  c++  java
  • tryfinally中的返回值

    class B
    {
        public int i=0;

    }


    public class MyTestCase {


        @Test
        public void hello() {
            int a = getI();
            System.out.println("a = " + a);
            
             B b1 = getB1();
            System.out.println("b1.i = " + b1.i);
            
            B b2 = getB2();
            System.out.println("b2.i = " + b2.i);
        }


        private int getI() {
            int a = 0;
            try {
                a = 1; 
                return a;
            } finally { 
                a = 2; 
            }
        }
        private B getB1() {
            B b = new B();
            try {
                b.i = 1; 
                return b;
            } finally { 
                b.i = 2;  
            }
        }
        
        private B getB2() {
            B b = new B();
            try {
                b.i = 1; 
                return b;
            } finally {  
                b = new B();
            }
        }
    }


    输出:

    a = 1
    b1.i = 2
    b2.i = 1

  • 相关阅读:
    餐盘模拟 数据结构及其描述
    游戏心理相关
    对于问题的认知过程
    程序语言中的基础理解
    游戏聊天记录
    游戏设定
    游戏技能学习
    游戏数值学习
    游戏的系统化思维
    游戏存储数据随笔
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276761.html
Copyright © 2011-2022 走看看