Wednesday 11 March 2015

ENUM


An enum is an abstract data type with values that each take on exactly one of a finite set of identifiers that you specify. Enums are typically
used to define a set of possible values that don’t otherwise have a numerical order, such as the suit of a card, or a particular season of
the year. Although each value corresponds to a distinct integer value, the enum hides this implementation so that you don’t inadvertently
misuse the values, such as using them to perform arithmetic. After you create an enum, variables, method arguments, and return types
can be declared of that type.


public enum Season {WINTER, SPRING, SUMMER, FALL}
Season e = Season.WINTER;

public Season m(Integer x, Season e1) {
if (e1 == Season.SUMMER) {
return Season.SUMMER;
}
else{
return Season.WINTER;
}
}

System.debug(m(1,Season.SUMMER));

No comments:

Post a Comment