{"id":280,"date":"2008-11-18T14:51:25","date_gmt":"2008-11-18T13:51:25","guid":{"rendered":"http:\/\/www.sahits.ch\/blog\/?p=280"},"modified":"2017-12-24T21:42:28","modified_gmt":"2017-12-24T20:42:28","slug":"work-around-protected-method-definitions","status":"publish","type":"post","link":"http:\/\/sahits.ch\/blog\/blog\/2008\/11\/18\/work-around-protected-method-definitions\/","title":{"rendered":"Work around protected method definitions"},"content":{"rendered":"<p>Sometimes you want to call a protected method but you class is not a subclass and neither in the same package.<br \/>\n<!--more--><br \/>\nThe obvious solution that comes to mind is to increase the visibility of the called method. This however may not be possible since you don&#8217;t own the class (e.g. part of a third part library) or even more important: <strong>Bad Design<\/strong>.<br \/>\nIf you cannot\/will not change the interface you are left with the possibility to wrap the call. To do this you simply define a private inner class that extends the class containing the method. From this inner class you can call the method. Now define a public method that wraps this call. Arguments and return values are passed through. This public method can now be called from your own code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you want to call a protected method but you class is not a subclass and neither in the same package.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[301,300],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-java","category-programmieren","tag-java","tag-programmieren"],"_links":{"self":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":3,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":2568,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/280\/revisions\/2568"}],"wp:attachment":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}