import static java.awt.BorderLayout.* ; container.add(component, CENTER); //instead of BorderLayout.CENTER
zmarak ahmad djan
Greenhorn
Joined: Sep 02, 2004
Posts: 20
posted
0
code number one will issue an error Borderlayout is not a package
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
posted
0
It's something I've been wishing for for a while. It can be used to make code more readable in a lot of cases. I'm particularly thinking of (a fairly common case in my experience) the following:
Using static imports this can be simplified to:
Typically in these kind of situations the package that the constant relates to is clear from the context and the actual constant name. The package name in these cases is just syntactic noise (opposite of sugar?).
The only arguments against the inclusion of static imports in Tiger that I've heard is that they can be abused. So name me a feature of Java that can't. :roll:
Jules
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
Unfortunately, the J2SE 5.0 static import mechanism is going to promote this kind of atrocity even further.
One should consider using a java.util.Map keyed by what would otherwise be the arguments to the case statements, whose values are of some abstract type that performs the common behaviour. Procedural programming constructs generally do not belong in an object-oriented language. [/PURISM]