Java 中:不允许逻辑操作、运算操作放在方法块外面,编译器会进行优化!!!

代码:

public class ProductLog {

    // 生产数据
    // 用于存放待随机的电话号码
    private List<String> phoneList = new ArrayList<>();

    public static void main(String[] args) {

    }
}

以上代码等价于:即编译对代码进行优化后的结果

public class ProductLog {

    // 生产数据
    // 用于存放待随机的电话号码
    private List<String> phoneList = null;

    public ProductLog() {
        this.phoneList = new ArrayList<>();
    }

    public static void main(String[] args) {

    }
}

相关文章:

  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-05-20
  • 2021-12-20
猜你喜欢
  • 2022-12-23
  • 2021-11-15
  • 2021-08-23
  • 2021-04-18
  • 2022-02-08
  • 2022-12-23
  • 2022-02-28
相关资源
相似解决方案