我在Java中发现了很多书籍,其中说switch语句比if else语句要快。但是我没有发现有其他地方在说为什么切换要比切换更快。例我有一种情况,我必须选择两项中的任何一项,我可以使用以下任一方式switch(item){case BREAD: //eat Breadbreak;default: //leave the restaurant}或使用如下的if语句if(item== BREAD){//eat Bread}else{//leave the restaurant}考虑项目和BREAD是恒定的int值在上面的示例中,哪个操作更快,为什么?
添加回答
举报
0/150
提交
取消