Abstract method in Enums

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…

Did you know that you can do that?

private static enum DynamicProperty {

    cacheManagerName {
        @Override
        void applyChange(final PropertyChangeEvent evt, final RuntimeCfg config) {
            config.cacheManagerName = (String) evt.getNewValue();
        }
    },
    defaultCacheConfiguration {
        @Override
        void applyChange(final PropertyChangeEvent evt, final RuntimeCfg config) {
            LOG.debug("Default Cache Configuration has changed, previously created caches remain untouched");
        }
    };

    abstract void applyChange(PropertyChangeEvent evt, RuntimeCfg config);
}

I think it’s nice because it allows you to customize Enum’s behavior or perform other actions on use.

Piece of code taken from EhCache Configuration (line 118 and further).

You May Also Like

Context menu or Action buttons ?

Recently I was drawn into one of those UI "religious" disputes that has no easy answers and usually both sides are right. One of our web developers was trying out new web tech (with pretty rich widget library) and started to question himself about some basic usability decisions. The low level problem in this case is usually brought to "which widget should I use ?". I'm not fond of bringing the usability problems to questions: Should I use Tabs over Menu ? Or should I use Context menu instead of buttons panel ? But sometimes if time is crucial factor and other usability levels are by default not addressed at all - better developer that asks those basic questions than developer that do not question himself at all.