forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverrideLesson.java
More file actions
34 lines (31 loc) · 889 Bytes
/
Copy pathOverrideLesson.java
File metadata and controls
34 lines (31 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package bestpractice;
import java.util.HashSet;
import java.util.Set;
//Always use Overrider, except extends abstract classes
public class OverrideLesson {
public static void main(String[] args) {
Set<Bigram> s = new HashSet<Bigram>();
for (int i = 0; i < 10; i++)
for (char ch = 'a'; ch <= 'z'; ch++)
s.add(new Bigram(ch, ch));
System.out.println(s.size());
}
}
class Bigram {
private final char first;
private final char second;
public Bigram(char first, char second) {
this.first = first;
this.second = second;
}
@Override
public boolean equals(Object o) {
if(!(o instanceof Bigram)) return false;
Bigram b = (Bigram) o;
return b.first == first && b.second == second;
}
@Override
public int hashCode() {
return 31 * first + second;
}
}