I'm trying to implement something in a semi-efficient manner. In my program, I have an enumerator representing metrics that are used to pass information around in the program.
I have a class that lets me "compose" these metrics into a single object so I can essentially create a "sentence" to give me complex information without having to do any complex parsing of information. They're essentially bit flags, but since I'm using an enum, I can have more than just 64 of them.
The problem is that if I'm instantiating instances of this container class a lot, and I go to create an array like so:
metrics = new boolean[Metrics.values().length];
I feel like creating an array of the enumerated values so often just to request its size is wasteful. I'm wondering if it's possible to just define the size of the enumerated values() in a static context so it's a constant value I don't have to recalculate:
private static final int METRIC_COUNT = Metrics.values().length;
Can I do this? Or would the compiler not have defined the enumerated values before it declares this static variable? I know this isn't the best explanation of my question, but I'm not sure how else to word it.
I know the static variable will be determined at runtime (unless the value assigned to it were a literal value), so would the program be able to request the members of the Metrics enum at this point in execution?