Skip to content

Commit 5ec9f9b

Browse files
author
Bruce Eckel
committed
new appendix
1 parent 5d0f0fe commit 5ec9f9b

28 files changed

+328
-172
lines changed

collectiontopics/Bits.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void printBitSet(BitSet b) {
1414
System.out.println("bit pattern: " + bbits);
1515
}
1616
public static void main(String[] args) {
17-
SplittableRandom rand = new SplittableRandom(47);
17+
Random rand = new Random(47);
1818
// Take the LSB of nextInt():
1919
byte bt = (byte)rand.nextInt();
2020
BitSet bb = new BitSet();

collectiontopics/CanonicalMapping.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class Element {
1111
@Override
1212
public String toString() { return ident; }
1313
@Override
14-
public int hashCode() { return ident.hashCode(); }
14+
public int hashCode() {
15+
return Objects.hashCode(ident);
16+
}
1517
@Override
1618
public boolean equals(Object r) {
1719
return r instanceof Element &&

collectiontopics/Prediction.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

collectiontopics/SpringDetector.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

collectiontopics/SpringDetector2.java

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// collectiontopics/ComposedEquality.java
1+
// equalshashcode/ComposedEquality.java
22
// (c)2017 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://OnJava8.com for more book information.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// collectiontopics/CountedString.java
1+
// equalshashcode/CountedString.java
22
// (c)2017 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://OnJava8.com for more book information.
@@ -41,8 +41,7 @@ public boolean equals(Object o) {
4141
Objects.equals(id, ((CountedString)o).id);
4242
}
4343
public static void main(String[] args) {
44-
Map<CountedString,Integer> map =
45-
new HashMap<>();
44+
Map<CountedString,Integer> map = new HashMap<>();
4645
CountedString[] cs = new CountedString[5];
4746
for(int i = 0; i < cs.length; i++) {
4847
cs[i] = new CountedString("hi");
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// equalshashcode/DefaultComparison.java
2+
// (c)2017 MindView LLC: see Copyright.txt
3+
// We make no guarantees that this code is fit for any purpose.
4+
// Visit http://OnJava8.com for more book information.
5+
6+
class DefaultComparison {
7+
private int i, j, k;
8+
public DefaultComparison(int i, int j, int k) {
9+
this.i = i;
10+
this.j = j;
11+
this.k = k;
12+
}
13+
public static void main(String[] args) {
14+
DefaultComparison
15+
a = new DefaultComparison(1, 2, 3),
16+
b = new DefaultComparison(1, 2, 3);
17+
System.out.println(a == a);
18+
System.out.println(a == b);
19+
}
20+
}
21+
/* Output:
22+
true
23+
false
24+
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// collectiontopics/Equality.java
1+
// equalshashcode/Equality.java
22
// (c)2017 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://OnJava8.com for more book information.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// collectiontopics/EqualityFactory.java
1+
// equalshashcode/EqualityFactory.java
22
// (c)2017 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://OnJava8.com for more book information.

0 commit comments

Comments
 (0)