本文介绍了Java参考分配与通用列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我觉得很蠢,要求我这样。
I feel stupid asking this but I am.
< MyCompany>
Now the list has broken the generic guarantee because you have list that was declared as <MyCompany> with a MyPerson in it.
b
$ b
You could cast it like this.
public void myMethod(List<MyCompany> list){ List<? extends HasId> ids = list; }
但不允许add()操作,如果你愿意,得到id。
But add() operations will not be permitted, but you can iterate it to get the id if you wish.
这篇关于Java参考分配与通用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!