17 September 2020

Type Inference and Anonymous Classes

The Kings of Sordid: Comparable and Comparator

Comparable<T> specifies compareTo This imposes the "natural ordering" on instances of the type T

Compararator specifies compare

Partially Ordered Sets

Caresian Product If A and B are sets, A X B is the set of all tuples (x,y) where x∈A and y∈B.

A relation R on a set S is any subset of S X S.

Let S = real numbers. Then < is the open half-plane below the line y = x. Equality is just the line y = x.

We write x R y for (x,y) ∈ R

Relations

Three important types of relations

compareTo puts a linear ordering on objects in a class.

x.compareTo(y) R 0 means x R y

where R is <= < > >=

compare(T x, T y) This must impose a linear ordering on the objects in T.

(x,y) -> x*x - y*y

x.compareTo(y) = - y.compareTo(x) is very desirable.