未验证 提交 b118cc4b 编写于 作者: B BrkingYan 提交者: GitHub

Update Java 基础.md

上级 d2a04c48
......@@ -63,8 +63,8 @@ boolean 只有两个值:true、false,可以使用 1 bit 来存储,但是
基本类型都有对应的包装类型,基本类型与其对应的包装类型之间的赋值使用自动装箱与拆箱完成。
```java
Integer x = 2; // 装箱
int y = x; // 拆箱
Integer x = 2; // 装箱 调用了 Integer.valueOf(2);
int y = x; // 拆箱 调用了 Integer.intValue(x);
```
## 缓存池
......@@ -78,6 +78,11 @@ new Integer(123) 与 Integer.valueOf(123) 的区别在于:
Integer x = new Integer(123);
Integer y = new Integer(123);
System.out.println(x == y); // false
Integer x = 123; //调用了Integer.valueOf(123);
Integer y = 123; //如果数值在[-128,127]之间,便返回指向缓冲池中已经存在的对象的引用;否则创建一个新的Integer对象。
System.out.println(x==y); //true
Integer z = Integer.valueOf(123);
Integer k = Integer.valueOf(123);
System.out.println(z == k); // true
......@@ -154,7 +159,7 @@ System.out.println(m == n); // true
## 概览
String 被声明为 final,因此它不可被继承。
String 被声明为 final,因此它不可被继承。(Integer等包装类也不能被继承)
在 Java 8 中,String 内部使用 char 数组存储数据。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册