30th use enum instead of int
In all, there are several advantages to using enum
1. Compile-time type safety,
2. Can be guaranteed to be the value of their own definition, there is no monthly risk,
3. Each enum type has its own namespace
4. Enumeration can add arbitrary methods and fields
5. The enumeration type is final and cannot be instantiated, that is, the instance is controllable.
31st Replace ordinal with instance field
That is, do not rely on enumerations to specify their values in order to define them, but should say that the enumeration is stored in an instance field, similar to the value of Xiamen:
Public enumRewardtype {RMB (1), OBJECT (2), ZAN (3), OTHERS (4), Noreward (5); Private Final intvalue; PrivateRewardtype (intvalue) { This. Value =value; } Public intGetValue () {returnvalue; }}
32nd use Enumset instead of bit field
The Enumset class is used to replace the bit field, and the specified enumeration value is written to a enumset type, which is read to know whether a particular enumeration value has been set
33rd replace ordinal index with Enummap
Which is the key to the map using the enumeration value.
35th annotations take precedence over naming patterns
37th Use Override
[Effective Java Reading notes] 6th Zhang Yi Lifting and annotations