duck.java

来自「深入浅出设计模式」· Java 代码 · 共 31 行

JAVA
31
字号
package headfirst.templatemethod.sort;public class Duck implements Comparable {	String name;	int weight;  	public Duck(String name, int weight) {		this.name = name;		this.weight = weight;	} 	public String toString() {		return name + " weighs " + weight;	}    	public int compareTo(Object object) { 		Duck otherDuck = (Duck)object;  		if (this.weight < otherDuck.weight) {			return -1;		} else if (this.weight == otherDuck.weight) {			return 0;		} else { // this.weight > otherDuck.weight			return 1;		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?