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

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

问题描述

我看到的阵列的最大尺寸可以是Int的唯一最大大小。为什么Java的不允许尺寸长最大的数组?

 长期没有= 10000000000L;
INT [] = NUM​​S新INT [无]; //这里的错误


解决方案

您必须解决为什么的问题Java的设计者。任何人都只能猜测。我的猜测是,他们认为双数十亿元素的数组应该足够任何人(其中,公平地说,它可能是)。

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

解决方案

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).

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

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