<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Foreach on Rowanto Luo</title><link>https://log.rowanto.com/categories/foreach/</link><description>Recent content in Foreach on Rowanto Luo</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Wed, 06 May 2015 17:06:16 +0000</lastBuildDate><atom:link href="https://log.rowanto.com/categories/foreach/index.xml" rel="self" type="application/rss+xml"/><item><title>The Difference between For-Each Loop and forEach()</title><link>https://log.rowanto.com/posts/the-difference-between-classic-foreach-and-java-8-functional-foreach-loop/</link><pubDate>Wed, 06 May 2015 17:06:16 +0000</pubDate><guid>https://log.rowanto.com/posts/the-difference-between-classic-foreach-and-java-8-functional-foreach-loop/</guid><description>
&lt;p&gt;People who have played enough with the brand new Java 8 will be familiar with the new &lt;a href="https://docs.oracle.com/javase/tutorial/collections/streams/"&gt;forEach(fn(x))&lt;/a&gt; loop in lambda. This syntax is quite popular among developers because it&amp;rsquo;s easier and prettier to use than the normal &lt;a href="https://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html"&gt;For-Each&lt;/a&gt; loop. It is also popular in other languages, especially JavaScript.&lt;/p&gt;
&lt;p&gt;The problem is, I&amp;rsquo;ve seen a very specific bug, which is related to this &amp;ldquo;functional&amp;rdquo; forEach() loop, quite a few times, again and again. People tend to think that these two kinds of loop are 100% identical, which is not. Although Java 8&amp;rsquo;s type-safety make it harder for people to make this mistake because of its compilation error, it&amp;rsquo;s still not 100% safe.&lt;/p&gt;</description></item></channel></rss>