Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `() -> A::new` is a function which returns a function which returns an A. (or, a function which returns a no-arg constructor)
- From [the spec](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.3)
- > A lambda expression is congruent with a [void-producing] function type
- > if ... the lambda body is either a statement expression (§14.8) or a
- > void-compatible block.
- So this function which returns a function **IS** an `IConverter` because it accepts no arguments, and even though it returns something, the item it returns is able to be ignored. That is, it's *void-compatible*.
- So the constructor is dropped on the floor and never invoked.
- What you meant was
- enum FactoryEnum {
- CLASS_A(A::new),
- CLASS_B(B::new);
- Now, it's not a function which returns a function. It's just a function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement