Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You want to create a location where some 4000+ constants will live. there's the possibility that users of this class may add constants (possibly at runtime)?. T</p> <ul> <li><p>Concern about the memory issues of statics is misplaced. If you need 4000 values, they're going to have to live somewhere, right? </p></li> <li><p>If people will be adding values at runtime, this sounds like a singleton Map or Properties (which is really just a kind of map anyway) of some kinds. People often use dependency injection frameworks like Spring or Guice to manage this sort of thing.</p></li> <li><p>If you just mean adding compile constants, you can make them all static. You'd probably want to make them static final as well, they'll be compiled inline.</p></li> <li><p>It's very likely that 4000 constants is a very bad idea. Where I've seen systems with large numbers of constants (>100, even) defined in one place, what usually happens is that people forget the definitions of them and end up using their own variants , which sort of defeats the purpose (for example, I've worked on a system with 100's of SQL queries defined in a "Queries" class. Of course people immediately ignore it as it's more of a bother to look up if the exact query you need is in there than to roll your own. The class eventually grew to something like 1500 queries, many exact duplicates and many unused, most used once. Utterly pointless). I can imagine exceptions where you wouldn't "lose" things with naming conventions, but unless you've got a use case like that this seems like a <em>really</em> bad idea.</p></li> <li><p>Breaking out your constants into enums gives you type-safe references. It also makes things conceptually easier to deal with. Compare:</p></li> </ul> <p>-</p> <pre><code>public class Constants { String WORK_ADDRESS; String WORK_PHONE; String HOME_ADDRESS; String HOME_PHONE; } </code></pre> <p>with </p> <pre><code>public enum ADRESS{ WORK, HOME } public enum PHONE { WORK, PHONE } </code></pre> <p>Which would you rather work with?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload