0

Hello I'm just wondering if there is anyone that could make sense of this java skeleton code table for an enum class. Table:

enter image description here

My code currently is this:

public enum SkyCondition
{
    SUNNY,
    SNOWY,
    CLOUDY,
    RAINY
}

Is that it? or am I supposed to incorporate the int in some way? Thank you.

ernest_k
  • 44,416
  • 5
  • 53
  • 99
  • 2
    Seems like `SkyCondition` was intended to be a bunch of old-style `int` constants in some class. But for a typical Java implementation, your code should be enough, as mentioned in Alex Rudenko's answer below. The only exception would be if your `int` values have to be set to specific, non-default, values. – ernest_k Nov 09 '21 at 18:41

1 Answers1

3

Every enum includes two properties by default:

public final String name(); // name like SUNNY, SNOWY, CLOUDY, RAINY
public final int ordinal(); // the position in enum declaration: 0 - for SUNNY, 1 - SNOWY, etc.

so, int is already incorporated into enum.

Nowhere Man
  • 19,170
  • 9
  • 17
  • 42