I want to find out if length property for Java arrays is an int/long or something else.
5 Answers
It is an int. See the Java Language Specification, section 10.7.
-
I really can't see anything forbidding the use of a long, for instance on a platform where that is more performant. You just can't index it with anything bigger than an int. It's a theoretical discussion at this point though. (Yeah, I saw the example but that's not normative). Commented Dec 15, 2010 at 19:10
In Java Language spec, Arrays you can see in 10.4:
Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion and become int values. An attempt to access an array component with a long index value results in a compile-time error.
I could not find the type of the length attribute, but it is at least an int; and if it's a long then you can not access elements beyond the max integer length.
So I guess it's a (final) int.
The data type is int, not long. Same as the index.
See http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html, 10.4
In JavaCard array indexes are shorts, but JavaCard is odd like that. Everywhere else, int like everyone else says.