How do you specify a byte literal in Java?
程序员文章站
2022-03-02 15:30:55
...
问题: If I have a method
void f(byte b);
how can I call it with a numeric argument without casting?
f(0);
gives an error.
答案:
You cannot. A basic numeric constant is considered an integer (or long if followed by a "L"), so you must explicitly downcast it to a byte to pass it as a parameter. As far as I know there is no shortcut.
f((byte)0);
查看原文:http://zccbbg.top/2017/05/24/specify-byte-literal-java/