While switch(null) is a compile error but switch(str) is fine (str being static final String str = null;).
Isn't static final String str = null; a compile-time constant which shall be substituted into switch(str) at compile time and thus be equivalent to switch(null)?
switch (null) { // compile Error immediately!
}
BUT:
public class Test {
// compile-time constant?
static final String s4 = null;
public static void main(String[] args) {
switch (s4) { // compiles fine! NPE at runtime
}
}
}
P.S. I suppose static final String str = null; IS NOT a compile-time constant, because only static final String str = 'string literal' is a compile-time constant, which explains example above (s4).