Re: Random Enum
markspace wrote, quoted or indirectly quoted someone who said :
No, it doesn't depend on the runtime type of e. No method is chosen.
"e.values()" is a syntax error. Period.
Roedy Green wrote:
I did a few experiments:
Enum<?> e. e.values() is a syntax error, cannot find symbol
Enum e. e.values. is a syntax error, cannot find symbol
TimeUnit.SECONDS.values(); even though values is static, works.
At first, I thought there must be some deep mystery, but I think all
it amounts to is class Enum has no static method "values()". It has no
need of one. However enum TimeUnit does.
markspace wrote at 12:39 EDT:
e.values() won't even compile. It's a static method declared on
subclasses of Enum, not Enum itself.
Let's go to the Javadocs, one of my favorite resolvers for Java library issues.
No 'values()' method shown.
What about the JLS, another great disambiguator?
In addition, if E is the name of an enum type,
then that type has the following implicitly declared static methods:
public static E values();
the automatically generated methods (values() and valueOf(String))
Whaddaya know? You guys are right, and so is the documentation! It tells us
that 'values()' is a method of each specific 'enum' type, automatically
generated for that type, and that 'Enum<E>' does not contain that method.
Sometimes the official documentation can be soooo helpful.