{"id":4908,"date":"2014-03-30T16:53:03","date_gmt":"2014-03-30T16:53:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/public-static-final-or-private-static-final-with-getter-collection-of-common-programming-errors\/"},"modified":"2014-03-30T16:53:03","modified_gmt":"2014-03-30T16:53:03","slug":"public-static-final-or-private-static-final-with-getter-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/public-static-final-or-private-static-final-with-getter-collection-of-common-programming-errors\/","title":{"rendered":"&#39;public static final&#39; or &#39;private static final&#39; with getter?-Collection of common programming errors"},"content":{"rendered":"<p>There&#8217;s one reason to not use a constant directly in your code.<\/p>\n<p>Assume FOO may change later on (but still stay constant), say to <code>public static final int FOO = 10;<\/code>. Shouldn&#8217;t break anything as long as nobody&#8217;s stupid enough to hardcode the value directly right?<\/p>\n<p>No. The Java compiler will inline constants such as Foo above into the calling code, i.e. <code>someFunc(FooClass.FOO);<\/code> becomes <code>someFunc(5);<\/code>. Now if you recompile your library but not the calling code you can end up in surprising situations. That&#8217;s avoided if you use a function &#8211; the JIT will still optimize it just fine, so no real performance hit there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s one reason to not use a constant directly in your code. Assume FOO may change later on (but still stay constant), say to public static final int FOO = 10;. Shouldn&#8217;t break anything as long as nobody&#8217;s stupid enough to hardcode the value directly right? No. The Java compiler will inline constants such as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4908","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4908"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4908\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}