我的客户类
中有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 类型??
时答案 0 :(得分:3)
您的Customer
班级有方法
public void setCustomerDetails(Collection<CustomersDetails> customerDetails) {
this.customerDetails = customerDetails;
}
您正尝试使用CustomersDetails
类型的参数调用它。 CustomersDetails
不是Collection<CustomersDetails>
。将元素换入List
或其他Collection
。
像
这样的东西customer.setCustomerDetails(Arrays.asList(customersDetails));