How come... part 1: importing statically
richard.warburton at gmail.com
Sat Jan 4 06:00:24 PST 2014
> but I can’t write:
> import static java.lang.System.out::printf;
> . . .
> printf("--(!)Error loading\n");
> What’s up with that?
import static let's you import static fields or methods with an abbreviated
syntax. printf isn't a static field or method - its an instance method of
the PrintStream class. On the other hand "out" is a static field of the
System class, so you can do:
import static java.lang.System.out;
What you asking for is a situation where "import static" imports things
that aren't static. This would almost inevitably lead to an alternative
"How come ..." question!
(This is part 1 in my How come... series, more parts as they come.)
I will observe that this question didn't really have anything to do with
lambda expressions and stack overflow deals very well with general Java
More information about the lambda-dev