Thursday, September 22, 2011

import static and enumerations

If you want to use the constants of an enumeration and do not want to prefix the constants of the enumeration by the enumeration name then you have to use import static.

Example :

public enum Enum1 {   
    value1
    ,value2
    ,value3;   
}
==========

import static Enum1.*;

public class Main {

    public static void main(String[] args) {
        Enum1 enum1 = value1;
    }
}

That's all folks !