GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaSourceCode/test/java/lang/IntegerTest.java at main · Kelab/JavaSourceCode

Expand file tree

/

IntegerTest.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
19 lines (18 loc) · 776 Bytes
/

IntegerTest.java

Copy path

File metadata and controls

19 lines (18 loc) · 776 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package java.lang;
/**
* IntegerCache 会缓存[-128,127]的 Integer(为了自动装箱的复用),valueOf 方法会从缓存中去拿值,如果命中缓存,会减少资源的开销
* 对象池模式:空间换时间
*
* @author wupx
* @date 2020/04/26
*/
public class IntegerTest {
public static void main(String[] args) {
Integer i1 = 66;// 通过反编译可以知道 Integer i = 66; 这种形式声明的变量是通过 java.lang.Integer#valueOf(int) 来构造 Integer 对象的
Integer i2 = 66;
Integer i3 = 128;
Integer i4 = 128;
System.out.println(i1 == i2);// true,在[-128,127]内时,会直接从 IntegerCache 中获取 Integer
System.out.println(i3 == i4);// false,属于两个对象
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.