简体   繁体   English

32位JVM和64位JVM之间的Integer.MAX_VALUE有区别吗?

[英]Is there difference for Integer.MAX_VALUE between 32bit JVM and 64bit JVM?

Is the value of Integer.MAX_VALUE different between 32bit JVMs and 64bit JVMs? 32位JVM和64位JVM之间的Integer.MAX_VALUE值是否不同?

I am compiling a Java class using 32bit JDK and deploy it on a 64bit machine. 我正在使用32位JDK编译Java类并将其部署在64位机器上。 I just want to make sure that I can rely on detecting if (aNumber == Integer.MAX_VALUE) . 我只想确保我可以依赖于检测if (aNumber == Integer.MAX_VALUE)

No. By definition Integer.MAX_VAlUE = 2^31 - 1 根据定义, Integer.MAX_VAlUE = 2^31 - 1

Integer.MAX_VALUE Integer.MAX_VALUE的

No. The 32-bit JDK makes 32-bit addresses for the instances, and the 64-bit JDK makes 64-bit addresses for the object instances. 否.32位JDK为实例生成32位地址,64位JDK为对象实例生成64位地址。 Thus, Integer.MAX_VALUE is the same, because it's just an value, not an object address. 因此,Integer.MAX_VALUE是相同的,因为它只是一个值,而不是一个对象地址。 :) :)

This constant has the same value regardless of whether the JVM the code is running on is 32-bit or 64-bit. 无论代码运行的JVM是32位还是64位,此常量都具有相同的值。 The documentation for Integer.MAX_VALUE describes this value as: Integer.MAX_VALUE文档将此值描述为:

A constant holding the maximum value an int can have, 2 31 -1. 保持int的最大值的常量可以是2 31 -1。

what all 32 bit and 64 bit resembles is the number of memory locations they can refer.. in case of 32 bit possible number of address will be 2^32 and in case of 64 bit it is 2^64. 所有32位和64位类似的是它们可以引用的存储器位置的数量。在32位可能的情况下,地址的数量将是2 ^ 32,而在64位的情况下,它是2 ^ 64。

The jvm version has nothing to do with Integer.MAX_VALUE , it will remain same. jvm版本与Integer.MAX_VALUE无关,它将保持不变。

You probably want to avoid comparing Integers using = sign due to: 您可能希望避免使用=符号比较Integers,原因如下:

Comparing Integers (provided aNumber is an object of class java.lang.Integer ) 比较整数 (假设aNumber是类java.lang.Integer的对象)

and no, there is no difference. 不,没有区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM