{"id":26694,"date":"2015-09-15T11:00:40","date_gmt":"2015-09-15T05:30:40","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=26694"},"modified":"2015-09-15T13:08:59","modified_gmt":"2015-09-15T07:38:59","slug":"why-you-should-stop-using-underscore-as-variable-name-in-java","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/why-you-should-stop-using-underscore-as-variable-name-in-java\/","title":{"rendered":"Why you should stop using underscore as variable name in Java"},"content":{"rendered":"<p>There is a programming practice in many languages that if in a function call you don&#8217;t care about the variable&#8217;s value then use _ to denote this. This convention is usually used where lambdas are used.<\/p>\n<p>Some people may be using this in Java also. If you are using it then you should stop. You must be asking why? Simply because underscore has been reserved for future use starting from JDK\u00a08.\u00a0Suppose you have the below<\/p>\n<div><\/div>\n<div>\n<p>[code]<br \/>\nvoid someMethod(int _) {<br \/>\n  \/\/ Something<br \/>\n}<br \/>\n[\/code]<\/p>\n<\/div>\n<div><\/div>\n<p>The above will give warning under JDK8 and as part of upcoming JDK 9 release this will become a compiler error. This is not a tentative change. It has been <a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8061549\">implemented<\/a> in JDK9 under <a href=\"http:\/\/openjdk.java.net\/jeps\/213\">JEP 213 &#8211; Milling Project Coin<\/a>. If you have many places where you are using _ as a convention then all of that will break.<\/p>\n<p>Using underscore in a variable like a_b is still valid. But using _ alone as variable name is no more valid.<\/p>\n<p>You have been warned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a programming practice in many languages that if in a function call you don&#8217;t care about the variable&#8217;s value then use _ to denote this. This convention is usually used where lambdas are used. Some people may be using this in Java also. If you are using it then you should stop. You [&hellip;]<\/p>\n","protected":false},"author":161,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":11},"categories":[446,1],"tags":[2369,2370],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/26694"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/161"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=26694"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/26694\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=26694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=26694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=26694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}