Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
New to Java 5.0... a real mixed blessing. Some people love this idea, some people hate it. Static imports exist only to save you some typing. If you hate to type, you might just like this feature. The downside to static imports is that - if you’re not careful - using them can make your code a lot harder to read.
The basic idea is that whenever you’re using a static class, a static variable, or an enum (more on those later), you can import them, and save yourself some typing.
Use Carefully: static imports can make your code confusing to read
Some old-fashioned code:
import java.lang.Math;
class NoStatic {
public static void main(String [] args) {
System.out.println("sqrt " + Math.sqrt(2.0));
System.out.println("tan " + Math.tan(60));
}
}