Java Reference
In-Depth Information
If a varargs method is declared such that this warning message occurs, and if the
varargsmethoddoesn'tperformapotentiallyunsafeoperationonitsvarargsparameter,
you can annotate the method @SafeVarargs , and eliminate the warning message.
Anenumeratedtypeisatypethatspecifiesanamedsequenceofrelatedconstantsas
itslegalvalues.Javadevelopershavetraditionallyusedsetsofnamedintegerconstants
to represent enumerated types.
Because sets of named integer constants have proven to be problematic, Java 5 in-
troducedtheenumalternative.Anenumisanenumeratedtypethatisexpressedviare-
served word enum .
You can add fields, constructors, and methods to an enum—you can even have the
enum implement interfaces. Also, you can override toString() to provide a more
usefuldescriptionofaconstant'svalue,andsubclassconstantstoassigndifferentbeha-
viors.
Thecompilerregards enum assyntacticsugarforaclassthatsubclasses Enum .This
abstractclassoverridesvarious Object methodstoprovidedefaultbehaviors(usually
for safety reasons), and provides additional methods for various purposes.
This chapter largely completes our tour of the Java language. However, there are a
fewmoreadvancedlanguagefeaturestoexplore.Youwillencounteracoupleofthese
minorfeaturesin Chapter4 , whichbeginsamultichapterexplorationofadditionaltypes
that are located in Java's standard class library.
Search WWH ::




Custom Search