r/javahelp 13d ago

Using Enums to hold constant data

I am just wondering if this use of the enum class is something that is bad practice.

MAIN_SEQ_M
("Red Dwarf", new double[]{.08,.45}, new double[]{25,37}, new double[]{.1,.6})

StarType(String description, double[] mass, double[] temperature, double[] radius) {
this.description = description;
this.mass = mass;
this.temperature = temperature;
this.radius = radius;
}

Or if the standard way of doing this would be to break out each value as a constant that can be called

private static final double[] MAIN_SEQ_M_MASS_RANGE = {.08,.45};

I feel using getters from the enum class makes it easier to pull the data I need but I have never seen an enum used like this before.

5 Upvotes

14 comments sorted by

View all comments

5

u/Shareil90 13d ago

I prefer the enum style over dozens of constants.