Sushant Kr
Sushant Kr

Reputation: 1973

Handling the static variable across the class

In my android project I have stored all my Constant fields in one class, and that class has grown big(25+ integer, 30+ String, 3 hash Map, and few array of String) collection of static variable. I did this because i need to access these values in different classes(not all).

Is this going to consume a lot of memory? Should i go with it?

Upvotes: 2

Views: 155

Answers (2)

Chandra Sekhar
Chandra Sekhar

Reputation: 16516

As @proflux told, For Storing constants you can use Enums.

1. When you need a fixed set of constants.
2. enums are type safe. With Strings all your items in all categories are the same type.
    There is nothing to stop you from feeding a fruit category to an animal parameter.
3. enums are Comparable and Serializable by default[Java 5]
4. Adding new enum constants, does not require re-compilation of the client code[Java 5]

You can find more information from here

Upvotes: 2

chrislatimer
chrislatimer

Reputation: 3560

I wouldn't worry much about the memory aspects, but from a maintainability standpoint those kinds of Constant classes can grow unwieldy over time. You might want to see if any of your constant values are good candidate for enums.

Upvotes: 1

Related Questions