Posted by cayhorstmann
on August 6, 2009 at 10:00 PM PDT
I would love to replace System.out.println with a static import and out.println in an introductory textbook, so that I could focus on objects and methods rather than what System.out means, but I am worried that it is considered too weird. What do you think?
I am rewriting a Java book for beginners, and it seems to make so much sense
import static java.lang.System.out;
public class Greeting
public static void main(String args)
I would no longer have to
dissect the awful
System.out.println("Hello, World!") expression.
(Ok, boys and girls.
System is a class.
a static field of type
PrintStream. That's another class. What is
static, you ask? It's what a TV set makes when it doesn't get a signal. No,
it's what you don't want in your dryer. Ok, whatever it is, you don't ever want
to do it in your code, unless it is also
final. That means, you
can't change it. Oh, you spotted
Ditto with mathematical expressions. Doesn't
sin(angle * PI / 180)
look so much nicer than
Math.sin(angle * Math.PI / 180)
Ok, at least to that tiny fraction of the population who knows
The fact is, I don't recall ever seeing anyone using static import outside
JUnit 4, where it is justifiably popular to import
I made a Google search, only to find a
href="http://www.davidflanagan.com/blog/000028.html">sensible blog whose
comments were filled with rants that static imports are the work of the
antichrist, something on
imports in C#, a
to use it rarely, and the usual certification garbage (
I am trying to get the reaction of the average Java coder here. Have you
out with a static import?
Would you think it weird to look at other people's code that did that? Or would
you welcome it?