2017-10-05 8 views
0

私のコンストラクタでこの問題が発生しています。サプライヤクラスからsupplierNameを取得して製品に追加したいと考えています。Javaレストコンストラクタ継承

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のエラーを与えてあります。

どのようなヘルプもうまくいくでしょう。

+2

どのようなエラーが表示されますか? –

+0

問題に発生しているエラーを追加することができれば助かります。問題の発生場所の行番号を含める必要があります –

+0

'Product'に一致するように引数を削除します – college1

答えて

1

あなたのコードの書式設定を編集する場合は、あなたが受け入れる、あなたはコンストラクタに文字列"Supplier1""supplier2"を解析しようとするはっきりと見ることができるオブジェクトを期待しているときは、"Supplier1"Supplier2に文字列を与えていますオブジェクトタイプとしてSupplier

は、あなたが定義したクラスSupplierを持っている場合は、へのコンストラクタの呼び出しを変更:

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) { .... } 

すべてのケースで結論は次のとおりです。は、書式設定を行ってください! :)

0

コンストラクタは"Supplier"