enum ShapeType {
CIRCLE {
@Override
public Supplier<Shape> create() {
return Circle::new;
}
},
RECTANGLE {
@Override
public Supplier<Shape> create() {
return Rectangle::new;
}
}
;
abstract Supplier<Shape> create();
}
final class Factory {
private Factory() {}
public static Shape getShape(final ShapeType type) {
return type.create().get();
}
}