Static String constants VS enum in Java 5+ -


I have read that question & amp; Answer:

And with a decision that the enum is a better way to implement a set of statics. Apart from this, I have read an example on the Sun Web site to add the behavior of enum (see link in the post mentioned earlier). Therefore, there is no problem adding string key with string key to keep a group of string values.

The problem here is that we need to add ".nameOfProperty" so that the string value So in code everywhere we need to address not only its name (EnumName.MY_CONSTANT) with constant value, but in this way (Enum.MY_CONSTANT.propertyName).

Am I okay here? What did you think about it?

Yes, naming can take a while, but no one can imagine as much ...

  1. Because the anonymous squares already give some context ( "what is the set of constants related?" ), Example name is usually less That constant name (strong typing has already been discriminated against by similar names in other names).

  2. In addition, you can use stable import to further reduce the length, you should not use it everywhere, by confusion To avoid, but I think a code that is deeply linked to it can be alright.

  3. In the switch , you do not use the class name. (Switches are not even possible on Java 7.)

  4. Only in enum squares , you use short names.

  5. Because in enums, many low-level codes that use the constants heavily, they migrate from business code to enum class (either dynamic or static method) can do. As we have seen, reducing migrating code in enum goes further than this.

  6. Constants are often treated in groups, such as if test of equality with one of the six constants, or four others etc. Enums are equipped with a system from EnumSets (or similar to a dynamic method that gives the right group), which as a group (As a secondary benefit, note that these two implementations of the group are exceptionally fast - O (1) - and with the following all these points, I found out that actual codes are too small

>

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -