Java Rest构造函数继承

Java Rest构造函数继承,java,rest,jersey,resteasy,Java,Rest,Jersey,Resteasy,我在我的构造函数中遇到了这个问题,我希望能够从supplier类中获取supplierName并将其添加到产品中 public class Product { private long id; private long barcode; private String description; private String zone; private int quantity; Supplier supplierName; publi

我在我的构造函数中遇到了这个问题,我希望能够从supplier类中获取supplierName并将其添加到产品中

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"));

    }
公共类产品服务{
私有映射产品=DatabaseClass.getProducts();
公共产品服务(){
产品。put(1L,新产品(1,1,“打火机”,“礼品”,5000,“供应商1”);
产品。投入(2L,新产品(2,2,“打火机”,“礼品”,3500,“供应商2”);
}
它给了我一个关于
供应商1
供应商2
的错误


任何帮助都会得到感谢。

您在
“Supplier1”
Supplier2
中给出字符串,而构造函数希望对象
“Supplier”
如果您编辑代码的格式,您可以清楚地看到您试图解析字符串
“Supplier1”
“Supplier2”
提交给构造函数,构造函数接受供应商作为对象类型

如果定义了类
供应商
,请将构造函数调用更改为:

products.put(2L,new Product(2,2, "Lighter","Gift",3500,new Supplier(...)));
或者,如果供应商应该是字符串,则更改其声明和构造函数

private String supplier;

public Product(long id, long barcode, String description, String zone, int quantity, String supplier) { .... }


所有情况下的结论都是:请进行格式化!:)

这会给您带来什么错误?如果您可以将收到的错误添加到您的问题中,这会很有帮助-它应该包括问题发生的行号删除与“产品”匹配的参数您可以分享
供应商
的外观吗?嗯,
字符串和供应商不兼容,即字符串不是供应商:
新产品(1,1,“打火机”,“礼品”,5000,“供应商1”)