optimization - What does Java compile an enumeration down to? -


A coworker and I were discussed about how Java shows the enumeration. I was under the impression that they were strictly like C / C ++ or, if you add behavior (type-safe enum), then it is wrapped in a class. He believed that if it is small, then Java will compact a byte.

However, I found it on the Oracle site:

The meaning of the Java programming language is far more powerful than their counterparts in other languages, which is slightly higher than the glorified integer The NUM declaration defines an integer class (an enum type is dubbed).

I think they are real objects, if that is so, is there any way to optimize them to save space?

Thanks

Edit: As stated in the comment on John's answer, I am after the ordering size of an enum

No, Java enum values ​​are actually objects they can have different implementations of methods based on fields, methods etc. - and per-value. However, there is only one set of them - it is not that you make yourself an example of anna; The set type of valid values ​​is built at the initial time. Unless you get the value of the value large , then it is not highly likely that you should also think about optimizing.

Note that one bit optimization that is is easy to acquire whenever you are considering a set of value values ​​logically. It basically uses a bit pattern to represent efficiently as determined.

(Note that C # is closer to C ++ than Java - C # AIs are unfortunately non-object oriented.)

Edit: Anonymous values ​​are ordered according to name :

Support for serialization has been added to handle enumerated types, which New in version 5.0 To serial an ANIM frequency, the rules are different from the rules for making the "normal" serial object serial: In the sequential form of the NM example, only its enum is continuous names, along with the identification of its base enum type. Deserialization is different with behavior - class information is used to find suitable enum class, and the Enum.valueOf method is called with that class and to get the constant for return Received continuous name

If you are actually following a small serialized form, then you should run Java explicitly with the built-in order, which is relatively verbose (as well as on version related issues Extremely sensitive). There are all types of options - one I know is the best, which does values ​​values ​​as if it considers the parameters as an integer.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

memcached - Django cache performance -