File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed
Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change 66
77 对于基本数据类型,只能使用 == 来进行比较,比较的是两个基本类型的值
88
9- 对于引用数据类型,== 比较的是内存地址值,equals 方法继承自object类,一般都需要重写 ,重写后一般比较的 是堆中的内容,比如string类和包装类都对equals方法进行了重写,如果没有重写,则比较的也是内存地址。
9+ 对于引用数据类型,== 比较的是内存地址值,equals 方法继承自object类,通常都会重写 ,重写后一般比较的 是堆中的内容,比如string类和包装类都对equals方法进行了重写,如果没有重写,则比较的也是内存地址。
1010
1111## 2. 自动装箱与拆箱
1212
13- 装箱:将基本类型用它们对应的引用类型包装起来
13+ 装箱:将基本类型用它们对应的引用类型包装起来,通过调用包装器的valueof()方法实现
1414
15- 拆箱:将包装类型转换为基本数据类型
15+ 拆箱:将包装类型转换为基本数据类型,通过调用包装器的xxxValue 方法实现(xxx代表对应的基本数据类型)
16+
17+ 常见的面试问题:
18+
19+ ``` java
20+ public class Main {
21+ public static void main (String [] args ) {
22+ Integer i1 = 100 ;
23+ Integer i2 = 100 ;
24+ Integer i3 = 200 ;
25+ Integer i4 = 200 ;
26+ System . out. printLn(i1 == i2); // true
27+ System . out. printLn(i3 == i4); // false
28+ }
29+ }
30+
31+ 通过阅读源码得知,在通过valueOf方法创建Integer 对象的时候,如果数值在[- 128 ,127 ]之间,便返回指向IntegerCache . cache中已经存在的对象的引用;否则创建一个新的Integer 对象。
32+ 上面的代码中i1和i2的数值为100 ,因此会直接从cache中取已经存在的对象,所以i1和i2指向的是同一个对象,而i3和i4则是分别指向不同的对象。
33+ ```
34+
35+
36+
37+ ## 3. 重载和重写的区别
38+
39+
40+
41+ ## 4. String、StringBuilder、StringBuffer 区别及使用场景
42+
43+ ## 5. final
1644
You can’t perform that action at this time.
0 commit comments