this key -- think in java notes
2014-10-16 21:38
288 查看
this 关键字对于将当前对象传递给其他方法很有用
class Person{ public void eat(Apple apple){ Apple peeled = apple.getPeeled(); //apple.getPeeled() == Peeler.peel(apple) == apple System.out.println("Yummy"); } } class Peeler{ //削皮 static Apple peel(Apple apple){ return apple; } } class Apple{ Apple getPeeled() { return Peeler.peel(this);} } public class TJ_5_41 { public static void main(String[] args){ new Person().eat(new Apple()); } }apple需要调用Peeler.peel()方法,他是一个外部工具方法,将执行由于某种原因必须放在Apple外部的操作.
相关文章推荐
- Think in java, notes
- think in java 读后感(一)
- 现在看的《c#技术内幕》与过去看的《Think In Java》两者的比较
- Think in java 答案_Chapter 2_Exercise 4
- Think in java 答案_Chapter 2_Exercise 11
- Think in java 答案_Chapter 2_Exercise 10
- think in java(3rd)读书笔记
- Think in java 答案_Chapter 3_Exercise 3
- Think in java &答案_Chapter 2_Exercise 2
- Think in java &答案_Chapter 2_Exercise 1
- Think in java 答案_Chapter 3_Exercise 1
- [Think in Java 笔记] 构造顺序
- 读"Think in Java"后笔记(1)
- Think in Java(12)-IO
- Think in java chapter's答案_Chapter 2_Exercise 3
- Think In JavaII 中文版下载(链接已修正)
- Think in java Stream 经典
- 【Notes】《Thinking in Java》【Chapter 11】Part II
- Think in java 答案_Chapter 2_Exercise 8
- Think in java 答案_Chapter 3_Exercise 2