#41 Implementing an Enum Alternative

Companies:
Yandex Ozon
Themes:
JavaOOPPractice

Write an alternative to Enum, as if before Java 1.5, using some enumerable list as an example, such as a list of currencies. It is necessary to:

  • Have a fixed list of values defined at compile time.
  • Have strict typing of values.
  • Be able to compare values safely using ==.
  • Retrieve all values.
  • Have an immutable ordinal, which is the zero-based sequence number in declaration order.
  • Retrieve values by ordinal.
  • Have a value name matching the field name of that value.
  • Search by name.

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in