Primitive streams and optional (original) (raw)

Brian Goetz brian.goetz at oracle.com
Wed Nov 21 07:08:23 PST 2012


Aside:: are we really allowing Foo::new as a "method" reference for a no-arg constructor? If so I think I'd prefer Foo::Foo. Isn't the point of the Factory<> interface to not have to do this? Or did I dream that?

The two are complementary. Constructor refs are a language feature, that allow you to get method-ref like functionality for constructors. Factory (now Supplier) is a functional interface that lets you use lambda/method ref of type () -> T in APIs. The two work together:

Factory fooFactory = Foo::new;

If we didn't have constructor refs, you'd have to write () -> new Foo() instead of Foo::new; if we didn't have Supplier it would be harder to represent "find/make me a T" in APIs.

(Other) David's comment was syntactic, that he thought Foo::Foo was a more obvious syntax for constructor refs than is Foo::new.



More information about the lambda-libs-spec-observers mailing list