Defining a constant in Java -
public enum categories { general, lights, effects, interactive, ui("ui"), optimizations, parsers, animation, materials, about; private string name; categories() { name = tostring().tolowercase(locale.getdefault()); name = name.substring(0, 1).touppercase(locale.getdefault()) + name.substring(1, name.length()); } categories(string name) { this.name = name; } public string getname() { return name; } }
inside enumeration first line starting "general, effects" wondering are? ui("ui"). meant constants? why ui("ui") have ( , ) when rest of them don't?
thanks in advance...
public enum categories { general, lights, effects, interactive, ui("ui"), ...
these represent enum
constants accessible qualifying them class name as
categories.general, categories.lights, categories.ui, ...
enums
behave lot class except meant representing constants. so, can have constructors , fields well. while general
used no-argument constructor
categories() { name = tostring().tolowercase(locale.getdefault()); name = name.substring(0, 1).touppercase(locale.getdefault()) + name.substring(1, name.length()); }
ui("ui")
used other overloaded constructor (since passed matching string argument)
categories(string name) { this.name = name; }
just class, enum
defines member field well
private string name;
which can accessed through public getter method as
categories.ui.getname();
Comments
Post a Comment