mkarneim / pojobuilder

A Java Code Generator for Pojo Builders
Other
334 stars 44 forks source link

Support Java 8 Supplier as withBuilderInterface #133

Closed drekbour closed 7 years ago

drekbour commented 7 years ago

PBs should be capable of implementing java.util.function.Supplier<T>. Currently I need to write:

/**
 * Supplier Facade for PojoBuilder.
 */
public interface SupplierBuilder<T> extends Supplier<T> {
    T build();

    default T get() {
        return build();
    }

    static <T> Collector<Supplier<T>, ?, List<T>> toSuppliedList() {
        return mapping(Supplier::get, toList());
    }

}

then give that as directive withBuilderInterface = SupplierBuilder.class

mkarneim commented 7 years ago

This looks perfectly good for me. I would do it the same.

What exactly do you want to change about this?

drekbour commented 7 years ago

Users don't want to have to have to write facades for this, however small. The value of PB over, say, and IDE-generated builder is the depth of features that can be added "just work".

withBuilderInterface = Supplier.class either as a special case (this is a language feature) or by generalising the public T build() check to public T <anything>()

mkarneim commented 7 years ago

Alright. I will add support for 'builder' interfaces that hava a get() method as an alternative to build().