Arrays are special objects in java, they have a simple attribute
named length which is final.
There is no "class definition" of an array (you can‘t find it in any .class file), they‘re a part of the language itself.
10.7. Array Members
The members of an array type are all of the following:
- The
publicfinalfieldlength, which contains the number of components of the array.lengthmay be positive or zero.The
publicmethodclone, which overrides the method of the same name in classObjectand throws no checked exceptions. The return type of theclonemethod of an array typeT[]isT[].A clone of a multidimensional array is shallow, which is to say that it creates only a single new array. Subarrays are shared.
- All the members inherited from class
Object; the only method ofObjectthat is not inherited is itsclonemethod.
It‘s "special" basically, with its own bytecode
instruction: arraylength. So this method:
public static void main(String[] args){
int x = args.length;
}
is compiled into bytecode like this:public static void main(java.lang.String[]);
Code:
0: aload_0
1: arraylength
2: istore_1
3: return
通过javap更好的说明了数组的length属性,其实是一个单独的二进制指令:arraylength
原文:http://www.cnblogs.com/onlywujun/p/3560017.html