The reason this does not work is that the value of the case
to switch on needs to be known at compile-time (because it is hard-coded and inlined in the bytecode).
String.class.getName()
is a method call that gets evaluated at runtime. Yes, static final
guarantees that it does not change after the class is initially loaded. But all that is long after compile-time.
The compiler never calls any code from application source code (with the possible exception of annotation processing). It only compiles it.