Warum werden für jeden Aufzählungstyp unterschiedliche Klassendateien erstellt, wenn sie über eine konstantenspezifische Methode verfügen?
Ich habe eine Aufzählung als
enum OperationsType {
ADD("+"), SUB("-"), DIV("/"), MUL("*");
private String opcodes;
private OperationsType(String opcodes) {
this.opcodes = opcodes;
}
public String toString() {
return this.opcodes;
}
}
Hier alle Aufzählungstypen haben keinconstant Specific method
sojavac
erstellt nur eine Klassendatei fürenum
wi
OperationsType.class
aber wenn ich @ hinzufüconstant Specific method
im gleichen Code für alle Aufzählungstypen dannjavac
erstellt 5 Klassendateien.
Operations.class
Operations$1.class
Operations$2.class
Operations$3.class
Operations$4.class
für unter Code
enum Operations {
ADD("+") {
public double apply(double a, double b) {
return a + b;
}
},
SUB("-") {
public double apply(double a, double b) {
return a - b;
}
},
DIV("/") {
public double apply(double a, double b) {
return a / b;
}
},
MUL("*") {
public double apply(double a, double b) {
return a * b;
}
};
private String opcodes;
private Operations(String opcodes) {
this.opcodes = opcodes;
}
public abstract double apply(double a, double b);
}
Also ich habe Zweifel, warumcompiler
hat für jedes @ 4 verschiedene Klassen angeleenum type
wenn sie @ habconstant Specific method
aber keine anderen Klassen erstellen, wenn sie kein @ habconstant Specific method
?