Skip to content
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

Using enums with a body as a Map key #643

Closed
mattharr opened this issue Jul 2, 2019 · 4 comments
Closed

Using enums with a body as a Map key #643

mattharr opened this issue Jul 2, 2019 · 4 comments
Assignees

Comments

@mattharr
Copy link
Contributor

mattharr commented Jul 2, 2019

Expected Behavior

When using a Map with an enum key, if one of the Enums has a body (i.e. a method defined in the individual enum declaration); the enum should still be able to be used as a key.

Current Behavior

Currently the MapCompositeConverter does not count this enum value as an enum.

Possible Solution

This change: master...mattharr:master
Looks to fix the issue, I looked at https://stackoverflow.com/questions/4166488/checking-if-a-class-is-java-lang-enum when looking into it.
However/additionally I think there may be other places in the codebase that use isEnum that could potentially have the same issue, but I wasn't sure.

Steps to Reproduce (for bugs)

This is when using an enum like:

private enum TestKeys {
    KEY1, KEY2 {
        @Override
        public String testMethod() {
            return "override";
        }
    };

    public String testMethod() {
        return "default";
    }
}

Your Environment

  • OGM Version used: 3.2 alpha06
  • Java Version used: 8
  • Neo4J Version used:
  • Bolt Driver Version used (if applicable):
  • Operating System and Version:
  • Link to your project:
@michael-simons
Copy link
Collaborator

🤯 Didn't know that. I personally use enums implementing an interface or having methods quite often, they really good as singletons. I'm gonna fix this ASAP.

@mattharr
Copy link
Contributor Author

mattharr commented Jul 3, 2019

Thanks for fixing that. Yes I was quite surprised too; I was using enums to define my fields, then added a method for special data migration for a field, and then it seems it was no longer an enum!?! 😃

@michael-simons
Copy link
Collaborator

That lead to a very interesting thread:

https://twitter.com/rotnroll666/status/1146316196876378112

Especially

https://twitter.com/jddarcy/status/1146512532296699904

Also Brians and Stuarts answers. I learned a ton.

@mattharr
Copy link
Contributor Author

mattharr commented Jul 5, 2019

Yes, interesting. Guess its pretty hard working on the JVM, an awful lot of things to think about. I guess it is technically correct, but is a surprising result for the function, I'd think there wouldn't be many people who would want it to return false when dealing with an Enum with a function, but that was the choice.

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

No branches or pull requests

2 participants