{"id":12102,"date":"2015-04-20T10:29:00","date_gmt":"2015-04-20T09:29:00","guid":{"rendered":"http:\/\/touk.pl\/blog\/?guid=845337c8ae1b7e96ba493e8eac178bde"},"modified":"2022-08-02T15:14:54","modified_gmt":"2022-08-02T13:14:54","slug":"abstract-method-in-enums-2","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2015\/04\/20\/abstract-method-in-enums-2\/","title":{"rendered":"Abstract method in Enums"},"content":{"rendered":"<p>Did you know that you can do that?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">private static enum DynamicProperty {\r\n\r\n    cacheManagerName {\r\n        @Override\r\n        void applyChange(final PropertyChangeEvent evt, final RuntimeCfg config) {\r\n            config.cacheManagerName = (String) evt.getNewValue();\r\n        }\r\n    },\r\n    defaultCacheConfiguration {\r\n        @Override\r\n        void applyChange(final PropertyChangeEvent evt, final RuntimeCfg config) {\r\n            LOG.debug(\"Default Cache Configuration has changed, previously created caches remain untouched\");\r\n        }\r\n    };\r\n\r\n    abstract void applyChange(PropertyChangeEvent evt, RuntimeCfg config);\r\n}<\/pre>\n<p>I think it&#8217;s nice because it allows you to customize Enum&#8217;s behavior or perform other actions on use.<\/p>\n<p><span style=\"font-size: x-small\">Piece of code taken from <a href=\"http:\/\/ehcache.org\/\">EhCache<\/a> <a href=\"https:\/\/fisheye2.atlassian.com\/browse\/ehcache\/branches\/ehcache-core-2.6.x\/src\/main\/java\/net\/sf\/ehcache\/config\/Configuration.java?hb=true\">Configuration<\/a> (line 118 and further).<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"Did you know that you can do that?  private static enum DynamicProperty {        cacheManagerName {            @Override            void applyChange(final PropertyChangeEvent evt, final RuntimeCfg config) {                config.cacheManagerName = (Str&#8230;\n","protected":false},"author":22,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[68],"class_list":{"0":"post-12102","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design","7":"tag-java"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=12102"}],"version-history":[{"count":5,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12102\/revisions"}],"predecessor-version":[{"id":14874,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12102\/revisions\/14874"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=12102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=12102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=12102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}