设计模式课程 设计模式精讲 19-3 策略模式源码解析
1 源码解析
1.1 源码解析1(jdk中的应用1)
1.2 源码解析2(jdk中的应用2)
1.3 源码解析3(Spring中的应用1)
1.4 源码解析4(Spring中的应用2)
1 源码解析
1.1 源码解析1(jdk中的应用1)
java.util.Comparator(策略类)作为比较器的应用
package java.util; public interface Comparator<T> { int compare(T o1, T o2); boolean equals(Object obj); }
java.util.ArrayList(策略类应用)
package java.util; import java.lang.reflect.*; public class Arrays { public static <T> void sort(T[] a, Comparator<? super T> c) { if (LegacyMergeSort.userRequested) legacyMergeSort(a, c); else TimSort.sort(a, c); } }
1.2 源码解析2(jdk中的应用2)
java.util.Comparator(策略类)作为比较器的应用
package java.util; public interface Comparator<T> { int compare(T o1, T o2); boolean equals(Object obj); }
java.util.TreeMap(策略类应用)
public class TreeMap<K,V> extends AbstractMap<K,V> implements NavigableMap<K,V>, Cloneable, java.io.Serializable { /** * The comparator used to maintain order in this tree map, or * null if it uses the natural ordering of its keys. * * @serial */ private final Comparator<? super K> comparator; final int compare(Object k1, Object k2) { return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2) : comparator.compare((K)k1, (K)k2); } }
相关推荐
瓜牛呱呱 2020-11-12
柳木木的IT 2020-11-04
yifouhu 2020-11-02
lei0 2020-11-02
源码zanqunet 2020-10-28
源码zanqunet 2020-10-26
一叶梧桐 2020-10-14
码代码的陈同学 2020-10-14
lukezhong 2020-10-14
lzzyok 2020-10-10
anchongnanzi 2020-09-21
clh0 2020-09-18
changcongying 2020-09-17
星辰大海的路上 2020-09-13
abfdada 2020-08-26
mzy000 2020-08-24
shenlanse 2020-08-18
zhujiangtaotaise 2020-08-18
xiemanR 2020-08-17