|
1 | 1 | package exceptionsAndAssertions;
|
2 | 2 |
|
3 | 3 | /**
|
4 |
| - * |
5 | 4 | * @author chengfeili
|
6 | 5 | * Jun 11, 2017 11:25:30 AM
|
7 | 6 | *
|
8 |
| - * An assertion is a Boolean expression that you place at a point in |
9 |
| - * your code where you expect something to be true. |
10 |
| - * |
11 |
| - * assert boolean_expression; assert boolean_expression: error_message; |
12 |
| - * |
13 |
| - * If assertions are disabled, Java skips the assertion and goes on in |
14 |
| - * the code. If assertions are enabled and the boolean expression is |
15 |
| - * true, then our assertion has been validated and nothing happens. The |
16 |
| - * program continues to execute in its normal manner. If assertions are |
17 |
| - * enabled and the boolean expression is false, then our assertion is |
18 |
| - * invalid and a java.lang.AssertionError is thrown. |
19 |
| - * |
20 |
| - * 1. Internal Invariants You assert that a value is within a certain |
21 |
| - * constraint. assert x < 0 is an example of an internal invariant. 2. |
22 |
| - * Class Invariants You assert the validity of an object’s state. Class |
23 |
| - * invariants are typically private methods within the class that return |
24 |
| - * a boolean. The upcoming Rectangle class demonstrates a class |
25 |
| - * invariant. 3. Control Flow Invariants You assert that a line of code |
26 |
| - * you assume is unreachable is never reached. The upcoming TestSeasons |
27 |
| - * class demonstrates a control ow invariant. 4. Preconditions You |
28 |
| - * assert that certain conditions are met before a method is invoked. 5. |
29 |
| - * Post Conditions You assert that certain conditions are met after a |
30 |
| - * method executes successfully. |
| 7 | + * An assertion is a Boolean expression that you place at a point in your code |
| 8 | + * where you expect something to be true. |
| 9 | + * |
| 10 | + * assert boolean_expression; assert boolean_expression: error_message; |
| 11 | + * |
| 12 | + * If assertions are disabled, Java skips the assertion and goes on in the code. |
| 13 | + * If assertions are enabled and the boolean expression is true, then our |
| 14 | + * assertion has been validated and nothing happens. The program continues to |
| 15 | + * execute in its normal manner. If assertions are enabled and the boolean |
| 16 | + * expression is false, then our assertion is invalid and a |
| 17 | + * java.lang.AssertionError is thrown. |
| 18 | + * |
| 19 | + * 1. Internal Invariants. You assert that a value is within a certain |
| 20 | + * constraint. assert x < 0 is an example of an internal invariant. |
| 21 | + * |
| 22 | + * 2.Class Invariants. You assert the validity of an object’s state. Class |
| 23 | + * invariants are typically private methods within the class that return a |
| 24 | + * boolean. |
| 25 | + * |
| 26 | + * 3. Control Flow Invariants. You assert that a line of code you assume is |
| 27 | + * unreachable is never reached. The upcoming TestSeasons class demonstrates a |
| 28 | + * control of invariant. |
| 29 | + * |
| 30 | + * 4. Preconditions. You assert that certain conditions are met before a method |
| 31 | + * is invoked. |
| 32 | + * |
| 33 | + * 5. Post Conditions. You assert that certain conditions are met after a method |
| 34 | + * executes successfully. |
31 | 35 | */
|
32 | 36 | public class Assertions {
|
33 | 37 | public static void main(String[] args) {
|
|
0 commit comments