1. 使用assert , 必須在java 后使用參數(shù)-ea
java -ea HelloWorld
2. 所以在eclipse中, 選擇run... 然后設(shè)置jvm參數(shù)-ea就ok了
注:assert的條件為假時(shí)觸發(fā)。