我真的找不到任何有关它的信息,这就是我在这里问的原因。 我试图弄清楚如果它与类具有相同的名称,它是什么类型的数组...例如:
public class ArrayOne {
int SomeInt;
ArrayOne [] arr;
public ArrayOne(SomeInt){
arr=new ArrayOne[1];
}
}
也许有人知道我在哪里可以读到它。非常感谢
最佳答案
如果你声明一个像这样的数组:
int[] myIntArray = new int[3];
你有一个int数组(记住java中的int不是对象)
所以如果你写:
ArrayOne[] arr;
您将拥有一个来自 ArrayOne 类的对象数组。
如果您仍然有疑问,可以像这样检查数组类型:
Class ofArray = o.getClass().getComponentType();
看这里:http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getComponentType--
public Class getComponentType()
Returns the Class representing the component type of an array. If this class does not represent an array class this method returns null.
关于Java 数组与类名同名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45743844/