一只1994

关注

How do you specify a byte literal in Java?

一只1994

关注

阅读 101

2023-04-11


问题: If I have a method

void f(byte b);
void f(byte b);

how can I call it with a numeric argument without casting?

f(0); gives an error.

答案:
f(0);

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);
f((byte)0);



相关推荐

东林梁

How do you install Google Chrome on Ubuntu?

东林梁 66 0 0

Mezereon

How do you force a CIFS connection to unmount

Mezereon 197 0 0

践行数据分析

UVA 10943 How do you add?——背包

践行数据分析 168 0 0

火热如冰

UVa 10943 How do you add? (组合数学)

火热如冰 34 0 0

云上笔记

JAVA interface报错:abstract methods do not specify a body

云上笔记 55 0 0

我是小瘦子哟

Ubuntu Tips: 显示php错误 How do you display PHP error messages?

我是小瘦子哟 76 0 0

天天天蓝loveyou

You must specify the value attribute or nested tag

天天天蓝loveyou 38 0 0

Mezereon

算法杂谈 How are you? I‘m fine Thank you ,and you?

Mezereon 163 0 0

捡历史的小木板

How do you setup / remove / modify Cluster Synchronization Services Daemon (CSSD) on a non-RAC syste

捡历史的小木板 205 0 0

诗尚凝寒

did you specify the right host or port报错处理

诗尚凝寒 164 0 0

精彩评论(0)

0 0 举报