How come... part 1: importing statically
Brian Goetz
brian.goetz at oracle.com
Sat Jan 4 18:22:04 PST 2014
> As before, a strong pointer-to-code similarity between lambdas and
> methods of both instance and static kinds let’s us neatly come back
> full circle and also write the above like. . . OK, so how come this
> is an error suddenly?
Your question is in the category of "how come horses don't have wings."
Here's what I imagine is going on in your head:
- You start out with "I really want to be able to just say println(x)";
- You imagine an alternate reality in which an existing language
feature means something else so it would enable you to write the code
you want to write;
- Then you ask "why doesn't it work that way."
Both the second and third steps are erroneous. Its entirely reasonable
to want to just say println(). But its not how things work, and despite
being wonky, "fixing" this bit of 1995-weirdness was not a goal, and
despite your examples with lambdas and method references, has absolutely
nothing to do with lambda.
I think if you study what import really means, you'll see it has a
straightforward and simple meaning.
If you really want to "just say println()", do this:
class MyUtilities {
public static void println(Object o) { System.out.println(o); }
...
}
...
import static MyUtilities.*;
and you're done. No need to distort the language.
More information about the lambda-dev
mailing list