Java中的数组有对应的类么,为什么数组可以直接调用clone()方法?
黄舟
黄舟 2017-04-18 10:13:08
0
3
667
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
刘奇

1. There is no class corresponding to an array in Java. Arrays are part of the Java language.
2. Data is a special object, which itself implements Cloneable. There is a sentence in the javadoc of Object's clone method: Note that all arrays are considered to implement the interface Cloneable, so arrays can be used directlyclone method. CloneableObjectclone方法的javadoc中有这么一句Note that all arrays are considered to implement the interface Cloneable ,所以数组是可以直接使用clone方法的。
3、数组对象天生就有一个finallength3. The array object inherently has a final length attribute. Because the array is not defined in any class, there is no source code.

Ty80

Java’s array is just an array, and there is no class corresponding to it.
Clone() used in arrays does not have to be a class. As long as the compiler provides this syntax, it can be implemented.
Similarly, the length of the array is also an array attribute parsed by the compiler. It is not implemented by Java, and naturally the source code of Java cannot be seen.

左手右手慢动作

Class c = int[].class;
System.out.println(c.getPackage());
System.out.println(c.getName());
System.out.println(Modifier.toString(c .getModifiers()));

It can be understood like this:
Array class is a set of special classes, dynamically generated by the JVM runtime, including its length attribute and other method implementations
In addition to int[], boolean[] such arrays,
also includes user-defined Arrays of defined types, such as arrays in the format of com.yourPackage.YourClass[], as well as 2-dimensional, 3-dimensional, and multi-dimensional arrays

There is an interesting input result
The modifier of the int[] class is public abstract final
This is beyond our knowledge

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template