我遇到一个构造函数的问题,该构造函数将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 <>"
我如何舍入(int)使得像(22536)这样的数字等于22000或23000?
我没有在Math类中找到一个特定的方法,Math.Round似乎只将double加倍到最接近的int.