Advertisement

在try...finally语句中返回计数器增1时的处理方式

阅读量:

前言

首先存在以下代码:

复制代码
    package hpsyche.string;
    
    /** * @author Hpsyche
     */
    public class MyTest {
    static Integer count=10;
    static Integer method(){
        return count++;
    }
    public static void main(String[] args) {
        System.out.println(method());
    }
    }
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

从输出结果来看,数值为10,这一结果具有合理性,程序首先返回count的值,随后执行自增操作;

引入

再观察以下示例:

复制代码
    public class MyTest {
    static Integer count=10;
    static Integer method(){
        try{
            r

全部评论 (0)

还没有任何评论哟~