EqualsHashCodeComparable.pptx

Download Report

Transcript EqualsHashCodeComparable.pptx

As You Arrive…
1. FIRST: Get today’s handout
2. SECOND: Snarf today’s code
3. THIRD: Take a look at StartOfClassExample. What is up with this code?
public void doExample()
{
List<Person> personList = getPersonList();
System.out.println("Person list: " + personList);
Person p = new Person("Mike","Hewner");
if(personList.contains(p)) {
System.out.println("Mike is in the list!");
} else {
System.out.println("Mike is not in the list?!? ");
}
}
private List<Person> getPersonList() {
List<Person> list = new ArrayList<Person>();
list.add(new Person("Mike", "Hewner"));
list.add(new Person("Benjamin", "Franklin"));
return list;
}
1. How to change the way equality
works in Java
2. How to change the way sorting
works in Java
One real example of overriding functions.
One real example of interfaces.
You’ll use both in Markov.
In the optional textbook
• Pages 549-567
• Be aware this also introduces
Comparator which is a slightly
different thing than
Comparable…just don’t get the
names mixed up