Auto inferred static imports
zhong.j.yu at gmail.com
Wed Feb 6 18:02:27 PST 2013
On Wed, Feb 6, 2013 at 6:52 PM, Stephen Colebourne <scolebourne at joda.org> wrote:
> I know this is too late, and its probably already been considered, but
> I haven't seen it mentioned anywhere. And it might trigger a
> Project Lambda appears to be defining a lot of helper static methods
> to go with the Stream API. Such as the Collectors class
> I'm assuming that the plan is to remove the static utility class and
> move the methods to the Collector interface (once the verifier is
> The use of code like this results in a need for lots of
> interface-qualified prefixing, or static imports
> someStreamThing.collect( Collectors.groupingBy(...) )
> someStreamThing.collect( groupingBy(...) ) // using a static import
On IntelliJ, when the cursor is inside "()" of a method invocation,
press Ctrl-Space will popup public static methods that return the
desire type; in this case, methods of Collectors. So writing the code
isn't much of a problem. Reading is another story - the question of
whether the word `Collectors` is a noise or a signal.
> We also have a similar design pattern in JSR-310 on TemporalAdjuster
> and TemporalQuery.
> It seems that "it would be nice" if the language could do this for us.
> Specifically, any static method on a functional interface (or maybe
> only @FunctionalInterface) is available for use at any call site that
> is target typed to that interface without any need for an explicit
> static import.
> someStreamThing.collect( groupingBy(...) ) // no need for a static import
> (no static import needed, because the method collect(Collector) takes
> a Collector, and the static method is on Collector.
> Of course an IDE can eliminate much of this pain anyway, so maybe its
> no big deal and not worth a language chaneg. But it does seem like a
> potentially useful extension to lambdas/Java. And perhaps it might
> stimulate another related idea. Since its too late for JDK 1.8, the
> only point I can suggest is a brief check to see if some other
> decision has made this an impossible feature.
More information about the lambda-dev