@Override public String toString(){ return"age:"+this.getAge()+",loginName:"+this.loginName +",realName:"+this.getRealName()+",career:"+this.getCareer(); } }
定义判断的接口:
1 2 3
publicinterfacePredicate<T> { booleantest(T t); }
定义选择函数:
1 2 3 4 5 6 7 8 9 10 11 12
publicclassSelectService<T> { public List<T> select(Collection<T> source, Predicate<T> predicate){ List result = new LinkedList(); for(T element:source){ if (predicate.test(element)) { result.add(element); } } return result; }
public List<T> select(Collection<T> source, PredicateFunction<T> predicate){ List result = new LinkedList(); for(T element:source){ if (predicate.test(element)) { result.add(element); } } return result; }
(List<String> list) -> list.isEmpty() //布尔类型表达式 () -> new Apple(10) //创建一个新对象 (Apple a) -> { System.out.println(a.getWeight()); } //使用一个对象的属性 (String s) -> s.length() //选择或提取一个对象的属性 (int a, int b) -> a * b //组合两个参数 (Apple a1, Apple a2) -> a1.getWeight().compareTo(a2.getWeight()) //比较两个对象
publicinthashCode(){ int h = hash; if (h == 0 && value.length > 0) { char val[] = value;
for (int i = 0; i < value.length; i++) { h = 31 * h + val[i]; } hash = h; } return h; }
TantanitReaderPhone的哈希值计算
1 2 3 4 5 6 7
@Override publicinthashCode(){ int result = 17; result = 31 * result + areaCode.hashCode(); result = 31 * result + localNumber.hashCode(); return result; }