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: |

The SSE was the first modern stock exchange to open in China, with trading commencing in 1990. It has now grown to become the largest stock exchange in Asia and the third-largest in the world by market capitalization, which stood at RMB 50.6 trillion (US$7.8 trillion) as of September 2021. Stocks (both A-shares and B-shares), bonds, funds, and derivatives are traded on the exchange. The SEE has two trading boards, the Main Board and the Science and Technology Innovation Board, the latter more commonly known as the STAR Market. The Main Board mainly hosts large, well-established Chinese companies and lists both A-shares and B-shares.

Mr. Durov launched Telegram in late 2013 with his brother, Nikolai, just months before he was pushed out of VK, the Russian social-media platform he founded. Mr. Durov pitched his new app—funded with the proceeds from the VK sale—less as a business than as a way for people to send messages while avoiding government surveillance and censorship.

Java from fr


Telegram Java
FROM USA