I have an optimization issue with my Java project. Here is the problem simplified for easier understanding:
First, let me mention that I have a simple ListBuilder
class that allows me to create Lists from multiple Lists.
I have an Enum class that contains animal variants:
public enum Variant {
HORSE_CLASSIC(...),
HORSE_VARIANT_1(...),
...
HORSE_VARIANT_N(...),
DOG_CLASSIC(...),
...
public void Variant(...) {
...
}
}
I have a Constants
class that groups common variants:
public class Constants {
public final static List<Variant> HORSE_STRIPED = Arrays.asList(Variant.HORSE_VARIANT_1, ...);
...
}
And finally, I have an Enum class that groups my animals:
public enum Animals {
HORSE(..., new ListBuilder<>(Arrays.asList(Variant.HORSE_CLASSIC).addList(Constants.HORSE_STRIPED).toList())),
...
public void Animal(...) {
...
}
}
The problem is that my Variant enum has heavy parameters that themselves call other builders, resulting in the Constants class initializing before the Variant Enums are fully instantiated. This causes the Constants class to have a null
object instead of the Variant enums. How should I handle this? I think my structure is quite chaotic and needs reworking, but what should it be replaced with? If anyone has an idea, I’m all ears.