java的引用数据类型的数组是否有继承关系?
怪我咯
怪我咯 2017-04-18 09:54:10
0
4
330

java中的数组是否有继承关系呢? String[] 是不是Object[] 的子类呢?


看了@MaxValue 发的链接http://www.zhihu.com/question... 之后, 我好像明白了一点, 数组之间不具有继承关系, 都是由jvm关联某一个特定类直接创建出来的, object[] a = new String[3] 应该是由编译器保证的. 不知道这么理解对不对

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
Ty80

I don’t know how to deal with this JDK, but it seems that there is an inheritance relationship.

public Object[] get(){        
    return new Integer[]{};
}

This works fine.

But classes with [] cannot be defined.

刘奇

No. An array is a collection of objects. Only objects have inheritance relationships

黄舟

string does inherit object, but it has nothing to do with arrays

左手右手慢动作

It can be understood that there is an inheritance relationship, and String[] instanceof Object[] will return true. But List<String> and List<Object> are two types, which are reflected at compile time and will be erased at runtime.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!