cast to byte, but why?

已回答

Look at the picture: 

Why does the Intellij complains to cast those two values to '(byte)', since they are so strictly encoded using '0b....' (it's Java) format?

IntelliJ IDEA 2021.3.3 (Community Edition)

 

0
Hi,

The java compiler itself would reject this code too.
The range of valid byte values is from -128 to +127. And `0b11111111` is 256 which is out of the byte range.
Also, see here for details: https://stackoverflow.com/q/38427664
0

请先登录再写评论。