gpt4 book ai didi

java - 构造函数未定义?枚举错误

转载 作者:行者123 更新时间:2023-12-02 11:08:06 29 4
gpt4 key购买 nike

public Tipo getTipo() {
return this.Importo < 0.0 ? Tipo.USCITA : Tipo.ENTRATA;
}

public int compareTo(Movimento m) {
if (this.idConto != this.idConto) {
return this.idConto - this.idConto;
}
return this.DataMov.compareTo(this.DataMov);
}

public static enum Tipo {
ENTRATA,// here i have this error : The constructor Movimento.Tipo() is undefined
USCITA;// here is the same : The constructor Movimento.Tipo() is undefined


private Tipo(String string2, int n2) {
}
}

我已经有了所需的构造函数,还需要编写什么?

最佳答案

我不确定如何定义枚举。基本上有两种解决方案:

1.不定义参数枚举

public static enum Tipo {
ENTRATA,
USCITA;
}

2.使用参数定义枚举
public static enum Tipo {
ENTRATA("Entrata", 1),
USCITA("Uscita", 2);

private String string;
private int integer;

private Tipo(String string, int integer) {
this.string = string;
this.integer = integer;
}
}

关于java - 构造函数未定义?枚举错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44367655/

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