G
Gast
Gast
Moin,
hab gerade ein static inner Klasse ausprobiert und bin begeistert.
Verwendet ihr solche Konstrukte oft bzw. bin ich auf der Suche nach Anwendungsfällen,
Habt ihr da einige Vorschläge?
hab gerade ein static inner Klasse ausprobiert und bin begeistert.
Verwendet ihr solche Konstrukte oft bzw. bin ich auf der Suche nach Anwendungsfällen,
Habt ihr da einige Vorschläge?
Code:
package javaapplication35;
public class Calculation {
public double calculate(double x, Operation operation, double y) {
return operation.eval(x, y);
}
public abstract static class Operation {
private String name;
public Operation(String name) {
this.name = name;
}
public abstract double eval(double x, double y);
public static Operation PLUS = new Operation("+") {
public double eval(double x, double y) { return x + y;}
};
public static Operation MAL = new Operation("*") {
public double eval(double x, double y) { return x * y;}
};
}
}