Friday, August 17, 2018

How to use enum in java

package com.javasampleapproach.angularjpamysql.controller;

public enum EnumTest {

    CODE01("01"),
    CODE02("02"),
    CODE03("03"),
    CODE04("04"),
    CODE01DESC("Retail Customer"),
    CODE02DESC("Retail Customer"),
    CODE03DESC("Retail Customer"),
    CODE04DESC("Retail Customer");

    private final String description;

    private EnumTest(String description) {
        this.description = description;
    }

    @Override    public String toString() {
        return description;
    }
}


package com.javasampleapproach.angularjpamysql.controller;

public class EnumCaller {
    public static void main(String args[]){
        System.out.println(EnumTest.CODE01);
        System.out.println(EnumTest.CODE01DESC);
    }
}

Output

01
Retail Customer

No comments:

Post a Comment