Skip to content

Solution # 1 - Enum function #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution # 1 - Enum function #9

wants to merge 2 commits into from

Conversation

gianlucatomasino
Copy link

No description provided.

@arialdomartini
Copy link
Contributor

Smart solution!
I didn't know that enum had that capability! It is really impressive!

It's apparent that the hardest part is the default execution path of the switch statement. @gianlucatomasino used a try/catch (which is somehow a hidden if)
I used a DefaultedMap and, guess what? Yes! It contains an if

  public Object More ...get(Object key) {
        // create value for key if key is not currently in the map
        if (map.containsKey(key) == false) {
            if (value instanceof Transformer) {
                return ((Transformer) value).transform(key);
            }
            return value;
        }
        return map.get(key);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants