简体   繁体   English

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

[英]The Constructor is undefined? Enum error

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) {
    }
}

I already have constructor that I need, what else I need to write? 我已经有了所需的构造函数,还需要编写什么?

You wrote a constructor that takes two arguments, but no default constructor. 您编写了一个带有两个参数的构造函数,但没有默认构造函数。 That means the compiler will not provide a no-arg constructor. 这意味着编译器将不会提供无参数的构造函数。 You should provide one or remove the private constructor. 您应该提供一个或删除私有构造函数。

I see no reason for the private constructor with two arguments. 我认为没有必要使用带有两个参数的私有构造函数。 You don't have any private data members in your enum. 您的枚举中没有任何私有数据成员。

Why is your enum static? 为什么您的枚举是静态的? Remove that. 删除它。

public enum Tipo {
    ENTRATA, USCITA;

}

I am not sure how do you want to define enum. 我不确定如何定义枚举。 There are basically 2 solutions to this: 基本上有两种解决方案:

1. Define no parameter enum 1.不定义参数枚举

public static enum Tipo {
    ENTRATA,
    USCITA;
}

2. Define enum with parameters 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;
    }
}

You are written wrong enum. 您写错了枚举。

public enum abc {

    ENTRATA("abc", 1),// here i have this error : The constructor Movimento.Tipo() is undefined
    USCITA("xyz", 2);// here is the same : The constructor Movimento.Tipo() is undefined


    private abc(String string2, int n2) {
    }

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM