Array-List里面的构造函数作为参数之一,如何创建一个新对象?

fra*_*pet 3 java constructor arraylist

我遇到一个构造函数的问题,该构造函数将arrayList作为参数之一.

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;
}    
Run Code Online (Sandbox Code Playgroud)

}

现在在我的类库中我想实例化一个新的ItemisedProductLine并将序列号的arryList传递给构造函数

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

这在Java中可行吗?这似乎不是一项常见的任务,没有找到任何例子.

作为替代方案,我可以使用通用数组而不是Array-List,但由于未知的大小,我无法初始化它

让我们希望我不会忘记另一个括号:-)

最后的事情是错误是"找不到合适的构造函数ArraList <>"

Edw*_*rzo 23

你可以尝试:

new ArrayList<String>(Arrays.asList("1233456", "6789123"))
Run Code Online (Sandbox Code Playgroud)