Private Static Finals vs. Private Finals

This question is asked here . According to the answer:

private final int NUMBER = 10;

If it cannot change, then there is no instance per instance.

My doubt is that if an instance of the class is created, say once a day, and it lasts a few seconds. Is it a good idea to store an int (in some case an object) in memory?

Assuming that there can be many such objects (20-30).

+4
source share
2 answers

How you store information depends a lot on what it is intended for use for.

There are several approaches you can take:

closed static final

, . , , ONCE.

, , , .

-, , .

public static int GetNumber() {...}

, , , , . , .

, ...

+3

private final int number, ,

,

. , :

private final int number;

public MyClass(int number) {
    this.number = number;
}

JDK .


, , static vs.

+2

Source: https://habr.com/ru/post/1533144/


All Articles