📜  java assert - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:42.091000             🧑  作者: Mango

代码示例1
public static void main(String[] args) {
        int a = 6;
        assert a != 6 : "a != 6";
    }
//Exception in thread "main" java.lang.AssertionError: a != 6

Foo result = null;
assert result != null;

final int result = a + b;
assert (result - a == b) : "Sum of " + a + " + " + b + " returned wrong sum " + result;