为什么 Java 在数字提升期间将字节和短操作数转换为整数

发布于 2024-10-10 03:11:57 字数 191 浏览 0 评论 0原文

数字推广流程?难道不能直接对这些较小的数据类型执行大部分操作吗?

What are the reasons behind the extension of small datatypes (e.g. byte) to int during the Numeric Promotion process? Wouldn't it be possible to perform most of the operations directly on these smaller datatypes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撕心裂肺的伤痛 2024-10-17 03:11:57

VM 是一个虚拟机,JIT 将其转换为本机代码,然后对其进行优化。所有寄存器都是 32 位或 64 位,“更短”的操作不一定更快。

The VM is a virtual machine, the JIT translates this to native code and optimises it then. All registers are either 32-bit or 64-bit and "shorter" operations are not necessarily and faster.

穿越时光隧道 2024-10-17 03:11:57

VM 不支持小于 4 个八位字节的整数,因此在 VM 中运行时,您将操作 4 个八位字节整数或 8 个八位字节长。 (它适用于数组、barray sarray 等,但不适用于单个值)。

The VM does not support integers smaller than 4 octets, so when running in the VM you are operating on 4 octet ints or 8 octet longs. (Well it does for arrays, barray sarray, etc, just not for single values).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文