我的客户类别中有使用getter和setter的实例
private Collection<CustomersDetails> customerDetails = new ArrayList<CustomersDetails>();
public Collection<CustomersDetails> getCustomerDetails() {
return customerDetails;
}
public void setCustomerDetails(Collection<CustomersDetails> customerDetails) {
this.customerDetails = customerDetails;
}
但是当我试图通过时
CustomersDetails customersDetails = new CustomersDetails();
customersDetails.set....
customersDetails.set....
Customer customer = new Customer();
customer.setCustomerDetails(customersDetails);
它给我错误
The method setCustomerDetails(Collection<CustomersDetails>) in the type Customer is not applicable for the arguments (CustomersDetails)
当我的收藏集为CustomersDetails类型时,为什么会这样呢?
最佳答案
您的Customer
类有一个方法
public void setCustomerDetails(Collection<CustomersDetails> customerDetails) {
this.customerDetails = customerDetails;
}
您正在尝试使用
CustomersDetails
类型的参数来调用它。 CustomersDetails
不是Collection<CustomersDetails>
。将元素包装在List
或其他Collection
中。就像是
customer.setCustomerDetails(Arrays.asList(customersDetails));