tag:blogger.com,1999:blog-3237724005744642470.post2701950856149367080..comments2014-09-05T21:54:37.641+01:00Comments on Captain Debug's Blog: Bad Habits with the equals() MethodRoger Hugheshttp://www.blogger.com/profile/07042290171112551665[email protected]Blogger1125tag:blogger.com,1999:blog-3237724005744642470.post-57952074371465312262013-05-03T09:33:47.676+01:002013-05-03T09:33:47.676+01:00An r-value is a literal which can only go on the r...An r-value is a literal which can only go on the right side of assignment operation, e.g. in expression<br /><br /> a = 5;<br /><br />a is an l-value, 5 is an r-value.<br /><br />Thus it is a generally good practice to use r-value <i>first</i> in any comparison operation. First, it&#39;s gonna be a constant and hence no null, second, if you make a mistake in int comparison and write it down as an assignment, it will be caught by the compiler.<br /><br />// hidden bug<br />if (a = 5) { ... }<br /><br />// obvious bug<br />if (5 = a) { ...}ve[email protected]