Monday, 15 April 2013

java - Why use static enum? -



java - Why use static enum? -

sometimes saw utilize static enum in android. can't find information(i know enum in c) example,

public static enum brush{ static{ array[0] = brush1; array[1] = brush2; array[2] = brush3; array[3] = brush4; } }

but occurred error in project. error message "syntax error, insert "identifier" finish enumconstantheader" don't understand that's mean.

the problem enum without list of members. you'd have:

public enum foo { value1, value2; }

you can have enum no members, still need semi-colon:

public enum foo { ; }

that's valid, although not terribly useful.

the static part in enum declaration presumably because it's nested within class. isn't required - nested enum declarations implicitly static.

the static { ... } static initializer, run when type initialized.

enums in java quite different in c. should read the enum section on java tutorial more details.

java static enums

No comments:

Post a Comment