Subtype Polymorphism 指的是可以使用父类类型的对象来引用子类类型的实例。 DIY Comparison 比较Object类对象时产生问题,如何比较???
考虑写一个比较器,比较两个Object对象
加深编译理解 Comparable Interface 1 2 3 public interface Comparable<T> { public int compareTo(T obj); } Comparator Interface 1 2 3 public interface Comparator<T> { public int compare(T obj1, T obj2); } 两者的关系↓ 总结
Java Libraries Collections Collections is a package in Java that provides various utility classes for working with collections. Tasks引入 3 tasks, given the text of a book:
Create a list of all words in the book. Count the number of unique words. Keep track of the number of times that specific words are mentioned. #1 way set 1 2 3 4 5 6 7 8 9 10 11 12 public static int countUniqueWords(List<String> words) { Set<String> ss = new HashSet<>(); for (String s : words) { ss.
Implementation Inheritance: Extends extends
Because of extends, RotatingSLList inherits all members of SLList: All instance and static variables. (注意public, private, protected的区别) All methods. All nested classes. Constructors are not inherited. super
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public class VengefulSLList<Item> extends SLList<Item> { private SLList<Item> deletedItems; public VengefulSLList() { deletedItems = new SLList<Item>(); } @Override public Item removeLast() { Item oldBack = super.