{"id":1042,"date":"2015-11-13T12:55:28","date_gmt":"2015-11-13T12:55:28","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1042"},"modified":"2015-11-13T12:55:28","modified_gmt":"2015-11-13T12:55:28","slug":"static-methods-arent-polymorphic","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/static-methods-arent-polymorphic\/","title":{"rendered":"Static methods aren&#8217;t polymorphic"},"content":{"rendered":"<p>While developing Java designers made a Mistake by allowing the static methods to get invoked by instance of a class.<\/p>\n<p>someVariable.SomeMethod() I expect it to use the value of someVariable. If SomeMethod() is a static method, that expectation is invalid.<\/p>\n<p>Language spec allows it like VB does and C# doesn&#8217;t.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass Base\r\n{\r\n    static void foo()\r\n    {\r\n        System.out.println(&quot;Base.foo()&quot;);\r\n    }\r\n}\r\n\r\nclass Derived extends Base\r\n{\r\n    static void foo()\r\n    {\r\n        System.out.println(&quot;Derived.foo()&quot;);\r\n    }\r\n}\r\n\r\npublic class Test\r\n{\r\n    public static void main(String&#x5B;] args)\r\n    {\r\n        Base b = new Derived();\r\n        b.foo(); \/\/ Prints &quot;Base.foo()&quot;\r\n        b = null;\r\n        b.foo(); \/\/ Still prints &quot;Base.foo()&quot;\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>While developing Java designers made a Mistake by allowing the static methods to get invoked by instance of a class. someVariable.SomeMethod() I expect it to use the value of someVariable. If SomeMethod() is a static method, that expectation is invalid. Language spec allows it like VB does and C# doesn&#8217;t. class Base { static void&hellip; <a href=\"https:\/\/codethataint.com\/blog\/static-methods-arent-polymorphic\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[142],"tags":[],"class_list":["post-1042","post","type-post","status-publish","format-standard","hentry","category-java-concepts"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1042"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1042\/revisions"}],"predecessor-version":[{"id":1043,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1042\/revisions\/1043"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}