Monday, February 11, 2013

Static imports

A static variable can be imported into a source file, since Java 5.0, which allows the static variable to be accessible without being prefixed with its corresponding class or interface name.

import static packagenames.classname.variablename;

E.g. of usage:

import static my.blueprints.House.counter;
import static java.lang.System.*;

class Test {
  public static void main(String [] args) {
    out.println(“counter = “ + counter);

No comments:

Post a Comment