“整数太大”对于一个小的编译时间常数
问题描述:
我有这个:
switch (account){
case 08120:
// Savings deposit interest rate
return null;
case 13100:
// Receivables contractual interest
return null;
case 16550:
// Default management process accounts payable
return null;
}
但编译器抱怨整数 08120
太大了!
But the compiler complains tha the integer 08120
is too large!
究竟发生了什么?
答
首先要做的事情是:不太可能你偶然发现了Java漏洞。首先归咎于你的代码。
First things first: it's unlikely you've stumbled across a Java bug. Blame your code first.
08120
是Java中的八进制文字,因为它启动前导零。
08120
is an octal literal in Java since it starts with a leading zero.
8不是有效的八进制数字(只有0到7)。
And 8 is not a valid octal digit (only 0 to 7 are).
因此,您会收到编译错误,尽管有点误导。
Therefore you get a compilation error, albeit a little misleading.