您的位置:首页 > 编程语言 > Java开发

How do you specify a byte literal in Java?

2017-05-24 09:51 357 查看
问题:

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.

答案:[/code]
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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐