有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

eclipse Java断言打印

当eclipse中的条件为true时,我需要将断言中的语句打印到控制台。 怎么做

public static void main(String[] args) {
    try {
        assert(args[0].equals("x")): "kate";
    } catch(Error e) {
        System.out.print("ae ");
    } finally {
        try {
             assert(args[0].equals("y")): "jane";
        } catch(Exception e2) {
             System.out.print("ae2 ");
        }
    }
}

共 (1) 个答案

  1. # 1 楼答案

    你需要:

    • 选择运行→ 运行配置→ 右键单击Java应用程序→ 新建→ 转到参数选项卡→ 在VM参数中写入-ea

    enter image description here

    现在,当你有这样的事情:

    assert(1==2) : "Error!!!";

    您将在控制台中看到:

    Exception in thread "main" java.lang.AssertionError: Error!!!
        at .....