加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 02:03:59 所属栏目:Java 来源:网络整理
导读:我遇到一个构造函数的问题,该构造函数将arrayList作为参数之一. public class ItemisedProductLine extends ProductLine{public static ArrayListString serialNumbers;public ItemisedProductLine(String productCode,double recRetPrice,double salePrice,
我遇到一个构造函数的问题,该构造函数将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;
}

}

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

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

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

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

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

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

解决方法

你可以尝试:

new ArrayList<String>(Arrays.asList("1233456","6789123"))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读