小编fra*_*pet的帖子

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

我遇到一个构造函数的问题,该构造函数将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 <>"

java constructor arraylist

3
推荐指数
1
解决办法
2万
查看次数

C#:如何将整数舍入到最接近的1000

我如何舍入(int)使得像(22536)这样的数字等于22000或23000?

我没有在Math类中找到一个特定的方法,Math.Round似乎只将double加倍到最接近的int.

c# math int rounding

1
推荐指数
1
解决办法
6055
查看次数

标签 统计

arraylist ×1

c# ×1

constructor ×1

int ×1

java ×1

math ×1

rounding ×1