Skip to content

Unable to find methods inside enum constants #131

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
rahlk opened this issue Apr 1, 2025 · 0 comments
Open

Unable to find methods inside enum constants #131

rahlk opened this issue Apr 1, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@rahlk
Copy link
Collaborator

rahlk commented Apr 1, 2025

Describe the bug
I'm trying to find and invoke methods that are defined within individual enum constants, but I'm unable to locate these methods.

To Reproduce
Steps to reproduce the behavior:

  1. Try to access methods defined in the enum constants

Example code with ToNumberPolicy enum implementing ToNumberStrategy:

public interface ToNumberStrategy {
  public Number readNumber(JsonReader in) throws IOException;
}

public enum ToNumberPolicy implements ToNumberStrategy {
  DOUBLE {
    @Override
    public Double readNumber(JsonReader in) throws IOException {
      return in.nextDouble();
    }
  },
  
  LAZILY_PARSED_NUMBER {
    @Override
    public Number readNumber(JsonReader in) throws IOException {
      return new LazilyParsedNumber(in.nextString());
    }
  },
  
  // Other enum constants with their own implementations...
}

Expected behavior
I expect to be able to find the readNumber method for each enum constant via reflection, as each constant has its own implementation of the method.

Additional context
The issue appears to be that each enum constant is actually an anonymous inner class of ToNumberPolicy.
However, I need to access these methods with codeanalyzer.

@rahlk rahlk added the bug Something isn't working label Apr 1, 2025
@rahlk rahlk self-assigned this Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant