我在構造函數中遇到這個問題,我希望能夠從供應商類獲取supplierName並將其添加到產品中。Java Rest構造函數繼承
public class Product {
private long id;
private long barcode;
private String description;
private String zone;
private int quantity;
Supplier supplierName;
public Product(){
}
public Product(long id, long barcode, String description, String zone,
int quantity, Supplier supplierName) {
super();
this.id = id;
this.barcode = barcode;
this.description = description;
this.zone = zone;
this.quantity = quantity;
this.supplierName = supplierName;
}
但是,當我到達我的產品服務類
public class ProductService {
private Map<Long, Product> products = DatabaseClass.getProducts();
public ProductService(){
products.put(1L,new Product(1,1,"Lighter","Gift",5000,"Supplier1"));
products.put(2L,new Product(2,2,"Lighter","Gift",3500,"supplier2"));
}
它給我一個錯誤的supplier1
& supplier2
問題所在。
任何幫助將appriciated。
它給你什麼錯誤? –
如果您可以將您收到的錯誤添加到您的問題中,它會很有幫助 - 它應該包括髮生問題的行號 –
刪除與「產品」匹配的論題 – college1