首页 新闻 会员 周边

泛型对象数组如何实例化(对象中有两个属性,其中一个继承了comparable)

0
悬赏园豆:80 [已关闭问题] 关闭于 2018-10-27 15:39

public class test3112<Key extends Comparable<Key>, Value> {

class Item{
Key key;
Value val;
}

private Item[] item;
private int n = 0;

public test3112(int capacity) {
item = (Item[]) new Comparable[capacity];//出现类型转换错误
}

就像空中月的主页 就像空中月 | 初学一级 | 园豆:9
提问于:2018-10-14 20:08
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册