有了 for (;;) ,为什么还需要while (true) ? 到底哪个更快?
往期热门文章:
来源:zhihu.com/question/52311366/answer/130090347
在JDK8u的jdk项目下做个很粗略的搜索:
mymbp:/Users/me/workspace/jdk8u/jdk/src$ egrep -nr "for \\(\\s?;\\s?;" . | wc -l369mymbp:/Users/me/workspace/jdk8u/jdk/src$ egrep -nr "while \\(true" . | wc -l323
while (1) {/* ... */}
public void foo() {int i = 0;while (true) { i++; }}/*public void foo();Code:stack=1, locals=2, args_size=10: iconst_01: istore_12: iinc 1, 15: goto 2*/
public void bar() {int i = 0;for (;;) { i++; }}/*public void bar();Code:stack=1, locals=2, args_size=10: iconst_01: istore_12: iinc 1, 15: goto 2*/
往期热门文章:
1、《历史文章分类导读列表!精选优秀博文都在这里了!》 2、Spring Boot + GraphQL 才是 API 的未来! 3、全员远程办公,半年入 1 亿美元:GitHub 的最大竞争对手上市了! 4、聊一聊Java 泛型通配符 T,E,K,V,? 5、各大公司程序员的工位,你中意哪一款? 6、Stackoverflow 高赞答案,为什么牛逼的程序员都不用 “ ! = null ' 做判空? 7、为什么不建议在MySQL中使用 utf8 ? 8、编写Spring MVC控制器的14个技巧!涨知识了! 9、日志打印的15个建议!血泪啊! 10、List中remove()方法的陷阱,被坑惨了!
评论
