aspose file tools
The moose likes Java in General and the fly likes Static import in jdk 5.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Static import in jdk 5.0" Watch "Static import in jdk 5.0" New topic
Author

Static import in jdk 5.0

Santosh Maskar
Ranch Hand

Joined: Jul 02, 2003
Posts: 226
hi
In jdk5.0 ther is a concept somthing called as static import , what this meas , i already read this documentation but not cleared

anybody ........knows how this static import in the application , why it needs really.
zmarak ahmad djan
Greenhorn

Joined: Sep 02, 2004
Posts: 20

so it's syntactic sugar
my advice: don't overuse (specifically don't overuse with static methods)


zmarak (publican)
Santosh Maskar
Ranch Hand

Joined: Jul 02, 2003
Posts: 226
Originally posted by zmarak ahmad djan:

so it's syntactic sugar
my advice: don't overuse (specifically don't overuse with static methods)



what is the differce between

import java.awt.BorderLayout.* ;
container.add(component, CENTER);

VS

import static java.awt.BorderLayout.* ;
container.add(component, CENTER); //instead of BorderLayout.CENTER
zmarak ahmad djan
Greenhorn

Joined: Sep 02, 2004
Posts: 20
code number one will issue an error
Borderlayout is not a package
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
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


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]


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Static import in jdk 5.0
 
Similar Threads
static imports
Static Imports
import
static import
IMPORTS Doubt