Advertisement
Guest User

Untitled

a guest
Nov 27th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. `() -> A::new` is a function which returns a function which returns an A. (or, a function which returns a no-arg constructor)
  2.  
  3. From [the spec](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.3)
  4.  
  5. > A lambda expression is congruent with a [void-producing] function type
  6. > if ... the lambda body is either a statement expression (§14.8) or a
  7. > void-compatible block.
  8.  
  9. 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*.
  10.  
  11. So the constructor is dropped on the floor and never invoked.
  12.  
  13. What you meant was
  14.  
  15. enum FactoryEnum {
  16.  
  17. CLASS_A(A::new),
  18. CLASS_B(B::new);
  19.  
  20. 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