Hacker News new | past | comments | ask | show | jobs | submit login

I agree (that’s what I meant under the more expressive part), though it is a bit more complex with identity in the way. Java’s enums are also the singleton pattern.

Java recently got ADTs as well in the form of sealed classes and records, here an enum would look like this:

  sealed interface Color permits Red, Blue, Green {
}

  record Red() {}
  record Blue() {}
  record Green() {}

You can now create as many Red instance as you want, they will be “equals” only under equals(), not under ==, while the latter is also true for the enum case.



The interface implementation types may include enums, though not sure that would help much in your example.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: