You could do the following: enum Sideīut we can't do this because Enum isn't an interface. Let's say that you want to create an enum of sides of the box model in CSS. Java conventions are that enum names are all uppercase, which immediately causes problems if you want to serialize the enum in another form. You can then turn around and use MyEnum.valueOf(String) to derive the original enum from a serialized form-but only if the string contains the getName() form. The way Java implements enums, the programming name of the enum is also the value returned by getName(), as wel as the default serialization returned by toString(). (I'm almost surprised Java didn't originally require FALSE=0 and TRUE=1 integers intead of an actual boolean type!) Now that Java has finally got around to add enums, there's plenty to like (ordinals, singletonality, use in case statements, to name a few things), but they still have some significant and needless shortcomings. ![]() Apparently Sun didn't appreciate the lowered project risk brought about by strongly-typed parameters-or care if the language made it just as easy to pass the direction integer argument SOUTH when the currency integer argument DOLLARS was expected. ![]() When Java was first introduced, it had a huge missing piece: enumerated types.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |