---------------------- ASP.Net+Unity开发、.Net培训、期待与您交流! ----------------------
所有具有相同元素类型和维数的数组都属于一个类型,即共享一个Class对象(一份字节码)。
怎样得到字节码(Class对象):
对象.getClass()
类名.class
Class.forName(包.类名)
package cn.itcast.day1;
import java.lang.reflect.*;
public class ReflectTest {
public static void main(String[] args) throws Exception {
int[] a1 = new int[2];
int[] a2 = new int[3];
int[][] a3 = new int[2][3];
String[] a4 = new String[3];
System.out.println( a1.getClass().equals( a2.getClass() ) );//true,这个可以用==号比较,下面两个不可以,会报错。
System.out.println( a2.getClass().equals( a3.getClass() ) );//false
System.out.println( a2.getClass().equals( a4.getClass() ) );//false
System.out.println( a1.getClass().getName() );//[I
}
}
注:
Cannot define dimension expressions when an array initializer is provided。
不能在一个数组已提供初始值时定义维表达式。
我们想直接打印出数组里面的内容,不用for循环,可以用Arrays中的一个方法asList将数组变成List,这样就可以直接打印出数组中的内容了。
Arrays 类中的方法&