Java 后缀分隔符
有必要使用后缀分隔符来表示源代码中使用的常量类型,例如 L 表示 long。然而,对于shorts和bytes没有分隔符,所以我需要像这样显式地转换常量值:
short x = (short)0x8000;
我想知道Java是否在编译的字节码中采取额外的步骤来实际将其从整数类型转换为short类型,或者是否这样做知道这将适合一个单词并按原样使用常量吗?否则,有没有办法可以后缀这样的数字来表示短或字节?
It's necessary to use a postfix delimiter to denote the type of constant being used in the source code, like L for long. However, for shorts and bytes there are no delimiters, so I need to explicitly cast the constant value like so:
short x = (short)0x8000;
I was wondering if Java takes extra steps in the compiled bytecode to actually convert this from an integer type to a short, or does it know that this will fit into a word and use the constant as is? Otherwise, is there a way I can postfix numbers like these to denote short or byte?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为它知道它适合一个单词并按原样使用它。例如字节码:
is (javac 1.6.0_14):
不。
I think it knows that it will fit into a word and uses it as is. For instance bytecode for:
is (javac 1.6.0_14):
No.