Is it possible to assign floating point values to enum in java?

ashwini :

I have a requirement in which I need to create a comb box containing floating point values like JBoss 4.2.3, JBoss 6.2 etc

I tried like below

public enum JBossVersion {

    UNKNOWN, JBOSS 4.2.3, JBOSS 6.2
}

But I get error each time saying ";" ,"," ,"}" expected

Can you guys help me how to proceed this further? If there is any approach please guide me. Thanks

ByeBye :

You can use private values in enum:

public enum JBossVersion {

    UNKNOWN(""),
    JBOSS_4_2_3("4.2.3"),
    JBOSS_6_2("6.2");

    private String version;

    private JBossVersion(String version) {
        this.version = version;
    }

    public String getVersion() {
        return version;
    }

}

And usage JBossVersion.JBOSS_4_2_3.getVersion()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=115797&siteId=1