This exercise is intended to get you to think about Liskov's argument about equals()
.
The following is "normal" Java:
Set<List<String>> s = new HashSet<List<String>>(); // AF(s) = ___ List<String> x = new ArrayList<String>(); // AF(x) = ___ List<String> y = new ArrayList<String>(); // AF(y) = ___ s.add(x); // AF(s) = ____ s.add(y); // AF(s) = ____ s.contains(y) // true or false? y.add("cat"); // AF(y) = ____ // AF(s) = ____ s.contains(y); // true or false? s.add(y); // AF(s) = ____ y.remove("cat"); // AF(s) = ____ s.remove(y); // AF(s) = ____ s.contains(y); // true, false, or something else?Fill in the values. What is the role of preconditions here?
Comparator
that reverses the natural ordering.
Comparator
contract?
comparator<Integer>
that uses absolute values.
comparator<Integer>
that orders evens before odds.