What's the purpose to bit-shift int value by zero?

bit-shift, java

Solution

I think I've solved it.

In the class JavaDocs:

// -- This file was mechanically generated: Do not edit! -- //

So it is not hand coded. It was script-generated and the script writer did not add an optimisation for the case when the amount to bit shift by is zero.

Problem

Looking to the source code of java.nio.DirectByteBuffer class, I have found this: ``` if ((length << 0) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) .... ``` What is the purpose to shift length by zero bits? May this be some perfomance optimization or something else?

Original source