Skip to content

Commit f111af8

Browse files
authored
Update 06-Housekeeping.md (#492)
从上下文阅读来看,这里应该是2
1 parent 7a425a2 commit f111af8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/book/06-Housekeeping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public class BananaPeel {
437437

438438
```java
439439
Banana.peel(a, 1)
440-
Banana.peel(b, 1)
440+
Banana.peel(b, 2)
441441
```
442442

443443
这是在内部实现的,你不可以直接这么编写代码,编译器不会接受,但能说明到底发生了什么。假设现在在方法内部,你想获得对当前对象的引用。但是,对象引用是被秘密地传达给编译器——并不在参数列表中。方便的是,有一个关键字: **this****this** 关键字只能在非静态方法内部使用。当你调用一个对象的方法时,**this** 生成了一个对象引用。你可以像对待其他引用一样对待这个引用。如果你在一个类的方法里调用其他该类中的方法,不要使用 **this**,直接调用即可,**this** 自动地应用于其他方法上了。因此你可以像这样:

0 commit comments

Comments
 (0)