0

After reading a lot about the wrappers' prebuilt cache, I was wondering if it would be very effective to use them as an alternative to the declaration of global constants.

That is, instead of:

public static final one = 1;

replace it with

Integer var = 1

sentence that would return the pre-built instance of Integer with value 1. The question is, would it be effective? or would it be the same? Thanks in advance

silvia Dominguez
  • 445
  • 1
  • 4
  • 16
  • 1
    What do you mean by "effective"? Memory-wise, an `int` will consume 32 bit, whereas the `Integer` will consume at least the size of a reference (save that the `Integer`-object will be created nontheless). Depending on your architecture, this will be either 32 or 64 bit. Performance-wise I would assume that the `int` performs better, since most CPUs have built-in instructions for integer arithmeitcs. – Turing85 Jan 04 '18 at 15:05
  • 2
    Not sure of the context of your question, but [consider using enum instead of constants](https://stackoverflow.com/questions/11575376/why-use-enums-instead-of-constants). – Andrew S Jan 04 '18 at 15:08
  • 2
    It really doesn't matter one "bit". You don't improve the efficiency of an application through such micro-optimization. – Kayaman Jan 04 '18 at 15:44

0 Answers0