{"id":4658,"date":"2014-03-30T14:21:17","date_gmt":"2014-03-30T14:21:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-does-checkstyle-suggest-that-i-use-a-final-method-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:21:17","modified_gmt":"2014-03-30T14:21:17","slug":"why-does-checkstyle-suggest-that-i-use-a-final-method-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-does-checkstyle-suggest-that-i-use-a-final-method-collection-of-common-programming-errors\/","title":{"rendered":"Why does CheckStyle suggest that I use a final method?-Collection of common programming errors"},"content":{"rendered":"<p>When you declare a method to be final, you&#8217;re saying that the method may not be overridden.<\/p>\n<p>Quote from the Java Language Specification:<\/p>\n<blockquote>\n<p>A method can be declared final to prevent subclasses from overriding or hiding it.<\/p>\n<p>It is a compile-time error to attempt to override or hide a final method.<\/p>\n<\/blockquote>\n<p>The common slogan (due to Joshua Bloch I believe) is<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;<em>Design and Document for Inheritance or Else Prohibit it<\/em>&#8220;<\/p>\n<p>So, unless you&#8217;re intention is to let subclasses override the method (and potentially change the behavior of the super-class (all methods are virtual in Java)) then make the method final.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you declare a method to be final, you&#8217;re saying that the method may not be overridden. Quote from the Java Language Specification: A method can be declared final to prevent subclasses from overriding or hiding it. It is a compile-time error to attempt to override or hide a final method. The common slogan (due [&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-4658","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4658","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=4658"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4658\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}