SE450: Assertions: Assertions Example [6/24] Previous pageContentsNext page

For the following code


public class MyClass {

    public static void main(String args[]) {
	assert false;
    }
}

Here is how it can be run using JDK 1.4

C:\temp>javac MyClass.java
MyClass.java:4: warning: as of release 1.4, assert is a keyword, and may not be used as an identifier
        assert false;
        ^
MyClass.java:4: not a statement
        assert false;
        ^
MyClass.java:4: ';' expected
        assert false;
               ^
2 errors
1 warning

C:\temp>javac -source 1.4 MyClass.java

C:\temp>java -classpath . MyClass

C:\temp>java -ea -classpath . MyClass
Exception in thread "main" java.lang.AssertionError
        at MyClass.main(MyClass.java:4)

C:\temp>

Previous pageContentsNext page