首页 > Linux操作系统 > Linux操作系统 > Java assert
assert logical_expresion;
assert logical_expresion: string_expresion;
example:
if(daysInMonth == 30){
System.out.println("Month is April, June, September, or November");
} else if(daysInMonth == 31){
System.out.println("Month is January, March, May, July, August, October, or December.");
} else{
assert daysInMonth == 28 or daysInMonth == 29
System.out.println("Month is Februay");
}
else if(daysInMonth == 28 or daysInMonth == 29){
System.out.println("Month is February");
}else{
assert false;
//or assert false: "daysInMonth has the value" + daysInMonth;
}
Above two sections in different colur are two different ways to fullfill the same function else satement.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24123206/viewspace-666780/ ,如需转载,请注明出处,否则将追究法律责任。