I was just asking myself a little question, and I'm not sure if I can find the right answer to this:
If I use an ENUM in Java, with an own constructor (and many, many, maaaaany parameters) - are those stored in Memory every time the program gets executed, or are they only 'loaded' in Memory, if they get used?
What I mean is, if I have an ENUM with 400 entries, and only use one of the entries - are all others still present in Memory?
some pseudocode:
public enum Type {
ENTRY_A(val1, val2, val3, val4, new Object(val5, val6, val7, ...)),
ENTRY_B(val1, val2, val3, val4, new Object(val5, val6, val7, ...)),
ENTRY_C(val1, val2, val3, val4, new Object(val5, val6, val7, ...)),
...
}
If I only use ENTRY_A, and dont touch ENTRY_B, ENTRY_C, etc - how will Java handle that exactly?
Thanks for the Answer - and yes, this is mainly curiousity
Yes everything will be loaded to memory even though you use only one ENUM constant.
Enum is special type of class and all fields are constants, so when you load the ENUM, then itself it loads everything to memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With