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

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Statements » assert 
5.13.2.The new assert keyword has the following syntax
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.