数组的最大大小 - 类型不匹配:无法从 long 转换为 int [英] Maximum size of an array - Type mismatch: cannot convert from long to int

查看:26
本文介绍了数组的最大大小 - 类型不匹配:无法从 long 转换为 int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到数组的最大大小只能是 Int 的最大大小.为什么 Java 不允许长度为 long-Max 的数组?

I see that the maximum size of an array can be only maximum size of an Int. Why does Java not allow an array of size long-Max ?

long no = 10000000000L;
int [] nums = new int[no];//error here

推荐答案

您必须向 Java 设计人员解决为什么"的问题.其他人只能猜测.我的猜测是,他们认为 20 亿个元素的数组应该对任何人都足够了(公平地说,这可能是).

You'll have to address the "why" question to the Java designers. Anyone else can only speculate. My speculation is that they felt that a two-billion-element array ought to be enough for anybody (which, in fairness, it probably is).

这篇关于数组的最大大小 - 类型不匹配:无法从 long 转换为 int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆