Does Java JIT compiler treat switch-over-final statements differently?

Viewed 56

Assume this demo piece of code:

public List<SomeObject> filter(List<SomeObject> objects, final EnumFilterType filter) {
  ArrayList<SomeObject> output = new ArrayList<SomeObject>();
  for (SomeObject subject : objects) {
    switch (filter) {
      /* whatever here */
    }
  }
  return output;
}

Here, filter is a final variable, which means it cannot be changed during code execution, which, in a perfect scenario, would let JIT perform more runtime optimizations, such as not generating the entire jump table and only generating the specific case matching the filter value. Does JIT perform such optimizations? If not, is there any reasoning behind that?

As a side note, the bytecode control flow isn't changed after being compiled(using JDT Core).

0 Answers
Related