Telegram Group & Telegram Channel
🚀 Java API Tip — Integer.valueOf() и кеширование 🚀

Знаешь ли ты, что Integer.valueOf(int) не всегда создаёт новый объект?

📦 Значения в диапазоне от -128 до 127 кэшируются!
Это значит, что:


Integer a = Integer.valueOf(100);
Integer b = Integer.valueOf(100);
System.out.println(a == b); // 👉 true (один и тот же объект)


Но:


Integer x = Integer.valueOf(200);
Integer y = Integer.valueOf(200);
System.out.println(x == y); // 👉 false (два разных объекта)


🔍 Почему так?

Чтобы повысить производительность и сэкономить память, Java автоматически кеширует часто используемые значения.

🛠 Кстати, ты можешь изменить границу кеша через JVM-опцию:


-XX:AutoBoxCacheMax=512


📌 Полезно, если у тебя в системе часто используются числа вне стандартного диапазона.

#Java #Performance #JVM #DevTips

@javatg



tg-me.com/javatg/1867
Create:
Last Update:

🚀 Java API Tip — Integer.valueOf() и кеширование 🚀

Знаешь ли ты, что Integer.valueOf(int) не всегда создаёт новый объект?

📦 Значения в диапазоне от -128 до 127 кэшируются!
Это значит, что:


Integer a = Integer.valueOf(100);
Integer b = Integer.valueOf(100);
System.out.println(a == b); // 👉 true (один и тот же объект)


Но:


Integer x = Integer.valueOf(200);
Integer y = Integer.valueOf(200);
System.out.println(x == y); // 👉 false (два разных объекта)


🔍 Почему так?

Чтобы повысить производительность и сэкономить память, Java автоматически кеширует часто используемые значения.

🛠 Кстати, ты можешь изменить границу кеша через JVM-опцию:


-XX:AutoBoxCacheMax=512


📌 Полезно, если у тебя в системе часто используются числа вне стандартного диапазона.

#Java #Performance #JVM #DevTips

@javatg

BY Java


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/javatg/1867

View MORE
Open in Telegram


Java Telegram | DID YOU KNOW?

Date: |

Importantly, that investor viewpoint is not new. It cycles in when conditions are right (and vice versa). It also brings the ineffective warnings of an overpriced market with it.Looking toward a good 2022 stock market, there is no apparent reason to expect these issues to change.

That strategy is the acquisition of a value-priced company by a growth company. Using the growth company's higher-priced stock for the acquisition can produce outsized revenue and earnings growth. Even better is the use of cash, particularly in a growth period when financial aggressiveness is accepted and even positively viewed.he key public rationale behind this strategy is synergy - the 1+1=3 view. In many cases, synergy does occur and is valuable. However, in other cases, particularly as the strategy gains popularity, it doesn't. Joining two different organizations, workforces and cultures is a challenge. Simply putting two separate organizations together necessarily creates disruptions and conflicts that can undermine both operations.

Java from us


Telegram Java
FROM USA