Java?????assert?????
???????????? ???????[ 2015/8/18 14:15:53 ] ??????????????????? ???????
???????????
??????C??C++?????ж???assert?????????????
??????Java?У???????assert???????????????÷?????嶼????
??????????
??????Java?У?assert????????JAVA SE 1.4 ???????????????汾??Java???????????assert???????′???Java????е??????????????????????????????е??????????????????????????????飬??????????-enableassertions??-ea???????
????assert???????????????????÷???
????1??assert <boolean????>
???????<boolean????>?true??????????????С?
????????false??????????AssertionError?????????С?
????2??assert <boolean????> : <???????????>
???????<boolean????>?true????????????С?
????????false??????????java.lang.AssertionError????????<???????????>??
??????????????
????????????????????????????????÷???
????public class AssertFoo {
????public static void main(String args[]) {
????//????1????true??????????????
????assert true;
????System.out.println("????1???????Go??");
????System.out.println("
-----------------
");
????//????2????false?????????
????assert false : "???????????????????????????????????????";
????System.out.println("????2???????Go??");
????}
????}
???????????C:AssertFoo.java????????????????У????????????????
????1?????????
????C:>javac AssertFoo.java
????2???????г?????п???-ea?????
????C:>java AssertFoo
????????1???????Go??
????-----------------
????????2???????Go??
????3??????-ea???????г???
????C:>java -ea AssertFoo
????????1???????Go??
????-----------------
????Exception in thread "main" java.lang.AssertionError: ????????????????????
???????????????????????
????at AssertFoo.main(AssertFoo.java:10)
???????????
????assert??????÷????????????assert??????????????????????????С????????á?????????о???????????????
????1??assert?????????????????????????????Ч????????????????κ????塣????????????Java IDE??????????п???-ea?????鸚???????ζ??????????IDE???????????????????????????鷳???????????Java Web?????????????????????????棬????????????????????У????????????-ea???????????????Web?????????????ò???????????????????????????????
????2????assert????if???????????assert???ж??if?????????????????????????????assert????????????????????????????????????С????assert??????????????????????????????????????assert???????ζ??????????????????????
????3??assert?????????????????????????????????????μ????????????????????????????????????????????????????????????Σ????????????????
?????塢??assert?????
????assert???????????????????????????????????????????????????????JUint?????????????JUint???assert?????????????????й????????????????????????IDE debug?????е???????????????assert???????譫??
?????????????????Java?????assert????????????Java?????????-ea???????????????????????£?assert?????????????????????鷳????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11