How does Java’s switch statement work under the hood? How does it compare the value of the variable being used, to those given in the case parts? Does it use == or .equals(), or is it something else entirely?
I’m mainly interested in the pre 1.7 versions.
Neither. it uses the
lookupswitchJVM instruction, which is essentially a table lookup. Take a look at the bytecode of the following example: