断言

断言是在Java 1.4中引入的。它能让你验证假设。如果断言失败(即返回false),就会抛出AssertionError(如果启用断言)。基本断言如下所示。

 基本语法:

assert expression1;
assert expression1: "错误提示";
    private int computerSimpleInterest(int principal, float interest, int years) {
        assert (principal > 0);
        return 100;
    }

 开启断言:虚拟机参数

-ea

原文地址:https://www.cnblogs.com/chenglc/p/8330111.html