I work with bit offsets in Java and have the following code snippet that works as expected:
final byte value = 1;
final int shift = 1;
byte result = value << shift;
This gives the value 2as expected. If, however, I try to extract this into a method like this:
private void shiftAndCheck(final byte value, final int shift) {
byte result = value << shift;
}
This results in a compilation error:
java: incompatible types: possible lossy conversion from int to byte
The question is, what is this method that causes this to fail?
source
share