Question

I want to find out if length property for Java arrays is an int/long or something else.

Was it helpful?

Solution

It is an int. See the Java Language Specification, section 10.7.

OTHER TIPS

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.

According to the specification, it's an 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top