Why is lambda return type not checked at compile time?
问题 The used method reference has return type Integer . But an incompatible String is allowed in the following example. How to fix the method with declaration to get the method reference type safe without manually casting? import java.util.function.Function; public class MinimalExample { static public class Builder<T> { final Class<T> clazz; Builder(Class<T> clazz) { this.clazz = clazz; } static <T> Builder<T> of(Class<T> clazz) { return new Builder<T>(clazz); } <R> Builder<T> with(Function<T, R>