[英]How can i solve the incompatible types error?
I try to add a list of things inside an array **我尝试在数组中添加一个列表 **
public Wrap(String name, Wrap wrap, List<Things> things) {
super(name);
this.bread = bread;
**things.addAll( Arrays.asList( things ) );**
}
** **
and I get this error: incompatible types.我收到此错误:类型不兼容。 Required
Collection<? extends topping>
必需的
Collection<? extends topping>
Collection<? extends topping>
but 'asList' was inferred to List<T>
:no instance(s) of type variable(s) exist so that List<topping>
conforms to Topping Collection<? extends topping>
但 'asList' 被推断为List<T>
:不存在类型变量的实例,因此List<topping>
符合 Topping
You are trying to call Arrays.asList()
on things
, which is already a List
.您正在尝试对已经是
List
things
调用Arrays.asList()
。 You can simply call addAll()
directly with things
:您可以直接使用
things
调用addAll()
:
public Wrap(String name, Wrap wrap, List<Things> things) {
super(name);
this.bread = bread;
things.addAll(new ArrayList(things));
}
However this doesn't make much sense to add things
to things
.然而,这对于向
things
添加things
没有多大意义。 Perhaps you have a class variable things
and meant to use the this
keyword?也许你有一个类变量的
things
并打算使用this
关键字?
this.things.addAll(things);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.