Question

Eclipse provides a feature to open the declarations of fields, invoked methods etc.

(F3 or Right click => Open declaration or Ctrl + click on the invoked method)

However, in the case of enum methods this feature doesn't function, e.g. MyEnum.values(); is called somewhere in my code and trying to open the declaration of values() with the combinations denoted above doesn't work obviously.

Why doesn't Eclipse open the declaration of such enum methods?

Était-ce utile?

La solution

Why doesn't Eclipse open the declaration of such enum methods?

Because they're not declared in source code at all. They're automatically supplied by the compiler - where would you expect to be taken? Ctrl-clicking on MyEnum (rather than the values() method) should open the enum with no problems though.

From section 8.9.3 of the JLS:

The members of an enum type E are all of the following:

  • ...
  • The following implicitly declared methods:

    /* javadoc... */
    public static E[] values();
    
    /* javadoc... */
    public static E valueOf(String name);
    

Note that the normal "go to declaration" techniques should work for any methods which genuinely exist in source code.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top