I fail to see the difference between a value class and an enumeration. It would be great if someone could tell me the difference between them and what the difference in their use is.
-
2What is value class – ThiepLV Jun 18 '16 at 08:09
-
2https://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html – Sander Jun 18 '16 at 08:25
-
Ask Google, get more information. – LowLevel Jun 18 '16 at 08:43
-
If I could find it on google I wouldn't ask it here. – Sander Jun 18 '16 at 08:52
1 Answers
First of all, it is not a "value class". It is a "value-based class". Please try to use the correct terminology.
The "Value-based Classes" blog entry by Nicolai Parlog explains in considerable detail what these are all about. In essence, they are a predecessor of "value types" that are likely to be added in a future version of Java. (Probably Java 10 - see Project Valhalla.)
The main reason that enum
types (in general) are not value-based classes is that they are not necessarily immutable. Immutability is one of the key requirements for a class to be value-based. (There are other aspects of enums that don't quite match up with the requirements, but the special nature of enum values probably mean that these would not matter.)
Right now, the "value-based class" characteristic has no direct use. But it may do in a future version of Java.

- 698,415
- 94
- 811
- 1,216
-
-
1Pretty much so. Compare the requirements and the properties of an enum class. (You be the judge ...) – Stephen C Jun 18 '16 at 12:22