为什么枚举构造函数不能在 Java 中受到保护或公开?
2022-08-31 12:22:19
整个问题都在标题中。例如:
enum enumTest {
TYPE1(4.5, "string1"), TYPE2(2.79, "string2");
double num;
String st;
enumTest(double num, String st) {
this.num = num;
this.st = st;
}
}
构造函数与默认或修饰符很好,但如果给定或修饰符,则会给我一个编译器错误。private
public
protected