gpt4 book ai didi

java - 类型不匹配 : cannot convert from double[][] to double[]

转载 作者:行者123 更新时间:2023-12-02 05:12:49 24 4
gpt4 key购买 nike

我对 Java 很陌生,这个问题刚刚出现,我尝试搜索但无法找出为什么会发生这种情况。

public class Cliente{

private int clientID;
private String clientName;
private double clientDebt;
private double[][] clientHistory;


public void registerID(int newID) {
this.clientID = newID;
}

// Here is the issue
public void newInvoice(double[][] invoice) {
this.clientHistory[this.clientHistory.length] = invoice;
}

}

最佳答案

您是否想跟踪发票数量不断变化的发票列表?如果是这样,您可能需要使用 ArrayList 。此类允许您添加新发票而不删除旧发票。你的类看起来像这样:

public class Cliente{

private int clientID;
private String clientName;
private double clientDebt;
private ArrayList<double[]> clientHistory = new ArrayList<double[]>();


public void registerID(int newID) {
this.clientID = newID;
}

// Here is the issue
public void newInvoice(double[] invoice) {
clientHistory.add(invoice);
}

}

关于java - 类型不匹配 : cannot convert from double[][] to double[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27204476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com