The new assert keyword has the following syntax : assert « Statements « SCJP






assert Expression1;
assert Expression1:Expression2;

Expression1 must have boolean type. 
Expression2 may have any type. 

If Expression1's value is true, no further action is taken. 
If Expression1's value is false, then an AssertionError is thrown. 
If Expression2 is present, it is converted to a String and used as the error's message.

public class MainClass {
  public static void main(String[] argv) {
    String title = null;
    assert isValidTitle();
    System.out.println();
  }

  static boolean isValidTitle() {
    return false;
  }

}








5.13.assert
5.13.1.Assertions give you a way to test your assumptions during development and debugging.
5.13.2.The new assert keyword has the following syntax
5.13.3.Assertion Command-Line Switches
5.13.4.Do Use Assertions to Validate Arguments to a Private Method
5.13.5.Use Assertions to Check for unreachable code