I was recently introduced to IntDef and StringDef interfaces by a co worker. I was using enums to maintain a list of constants for some purpose and he suggested me to use these interfaces. I went ahead to read more on that and would be sharing here what I learned. So, it turns out that enums often require more than twice as much memory as static constants (quoted from andev docs ). They are class objects, so : A single reference to an enum constant occupies 4 bytes Every enum occupies space that is the sum of all its fields’ sizes and overhead of an object the class itself occupies some space. Whereas constants require fixed space, 4 bytes in case of an int constant and (num of chars) * 1 bytes in a string constant. That said, we can replace enums with constants only in cases where we are just using them as constants. In cases where we are storing more (or complex data) data in enums, or using method overloading (every enum constant can have it’s own implementation of a ...
As the title says, I usually use this blog to put down what's currently going on in my life.