首页 > 有没有一个UUID,它的hashcode刚好等于Integer.MIN_VALUE

有没有一个UUID,它的hashcode刚好等于Integer.MIN_VALUE

public static void main(String[] args) {
		String uuid = null;

		do {
			uuid = UUID.randomUUID().toString().replace("-", "");
		} while (uuid.hashCode() != Integer.MIN_VALUE);

		System.out.println(uuid);
	}

你看,这个uuid,变成字符串,脱掉“-”之后,它的hashcode 刚好等于Integer的最小值。

然后我有个方法刚好是要取这个结果的绝对值,

Math.abs(Integer.MIN_VALUE)是负的有没有。

我就想弱弱的问一下,这样的UUID存在吗?

希望不要用比较值域大小范围的方式,来告诉我答案。


Math.abs(Integer.MIN_VALUE)为负很正常啊,溢出了撒。
因为Integer.MIN_VALUE=-2147483648,按理说它的绝对值应该是2147483648,
但是2147483648超出了整数interger的范围,所以就被表示成了负数。


有,359533051729330的hashcode为-2147483648

【热门文章】
【热门文章】