膳绫擎的Pet类持续自Individual,Individual类的的实现稍微复杂一点,我们实现了Comparable接口,从新自定义潦攀类的比较规矩,如不雅不是很明白的话,也没有关系,我们已经将它抽象出来了,所以不睬解实现道理也没有关系。
- public class Individual implements Comparable<Individual> {
- private static long counter = 0;
- private final long id = counter++;
- private String name; // name is optional
- public Individual(String name) { this.name = name; }
- public Individual() {}
- public String toString() {
- return getClass().getSimpleName() + (name == null ? "" : " " + name);
- }
- public long id() { return id; }
- public boolean equals(Object o) {
- return o instanceof Individual && id == ((Individual)o).id;
- }
- public int hashCode() {
- int result = 17;
- if (name != null) {
- result = 37 * result + name.hashCode();
- }
- result = 37 * result + (int
推荐阅读
常见用法: netstat –npl 可以查看你要打开的端口是否已经打开。 netstat –rn 打印路由表信息。 netstat –in 供给体系上的接口信息,打印每个接口的MTU,输入分>>>详细阅读
本文标题:Java反射机制应用实践
地址:http://www.17bianji.com/lsqh/35285.html
1/2 1