本文介绍了转换Collection< MyType>收集<对象>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public UniqueField(Collection< Object> items){ this.items =物品; }
Collection< Object> 是我可以使用集合< OtherType> 。
在做:
集合< OtherType> collection = ... UniqueField(collection);我得到无效参数的编译错误。如何解决这个问题?
解决方案您必须使用它而不是
public UniqueField(Collection< ;? extends Object> items){ this.items = items; }或?因为它等于?extends Object
public UniqueField(Collection<> items){ this .items =物品; }你可以看到这里为原因
I have a class with the following constructor:
public UniqueField(Collection<Object> items) { this.items=items; }The idea behind the Collection<Object> is that I would be able to use Collection<OtherType>.
When doing:
Collection<OtherType> collection=... new UniqueField(collection);I getting a compile error of invalid argument. How can I fix this?
解决方案You have to use this instead
public UniqueField(Collection<? extends Object> items) { this.items=items; }or ? because it is equal to "? extends Object"
public UniqueField(Collection<?> items) { this.items=items; }You can see here for the reason
更多推荐
转换Collection< MyType>收集<对象>
发布评论