Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array-List inside constructor as one of the parameter, how to create a new object?

i am having problem with a constructor that takes an arrayList as one of the arguments.

public class ItemisedProductLine extends ProductLine{

public static ArrayList<String> serialNumbers;

public ItemisedProductLine(String productCode, double recRetPrice, double salePrice, int quantity, String description, ArrayList<String> SerialNumbers){
    super( productCode,  recRetPrice,  salePrice,  quantity,  description);
    this.serialNumbers = serialNumbers;
}    

}

Now in my class Inventory i want to instantiate a new ItemisedProductLine and pass an arryList of serial number to the constructor

ItemisedProductLine item = new ItemisedProductLine("productCode", 2600, 2490, 2, "descrpition", new ArrayList<String>("1233456", "6789123"));

Is this possible in Java? It seem to be not a common task to do, did not found any example.

As alternative i could have used an generic array instead of Array-List but then i can not initialize it because of the unknown size

Let's hope i'm not forgetting another parenthesis :-)

Last Thing is the error is "no suitable constructor found ArraList<>"

like image 685
fra pet Avatar asked Nov 28 '22 09:11

fra pet


1 Answers

You could try:

new ArrayList<String>(Arrays.asList("1233456", "6789123"))
like image 73
Edwin Dalorzo Avatar answered Dec 15 '22 06:12

Edwin Dalorzo