According Oracle's documentation on Switch, a switch-case structure can work with some numerical primitives like byte, short, char and int (and their wrapper classes), as well as String and enums.
It's also true that enum classes automatically get a .ordinal()
method that returns the constant's position in its enum declaration.
Is it the case that, when enums are used in a switch-case structure, specifically in the case VENUS:
kind of label, that behind the scenes, the .ordinal()
method is being automatically called during compilation? Much like how .toString()
gets called in println()?
It's not explicitly stated in the documentation I've looked at what exactly happens or how it's possible that a switch statement, which (ignoring String) typically works with numerical primitives (via autoboxing if necessary), can work with an enum constant.