forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypedBin.java
More file actions
37 lines (36 loc) · 904 Bytes
/
TypedBin.java
File metadata and controls
37 lines (36 loc) · 904 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
35
36
37
// patterns/doubledispatch/TypedBin.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// A List that can grab the right type.
package patterns.doubledispatch;
import patterns.trash.*;
import java.util.*;
public class TypedBin {
private List<Trash> typedBin =
new ArrayList<>();
public final String type;
public TypedBin(String type) {
this.type = type;
}
public List<Trash> bin() {
// Returns a copy of typedBin:
return new ArrayList<Trash>(typedBin);
}
protected boolean addIt(Trash t) {
typedBin.add(t);
return true;
}
public boolean add(Aluminum a) {
return false;
}
public boolean add(Paper a) {
return false;
}
public boolean add(Glass a) {
return false;
}
public boolean add(Cardboard a) {
return false;
}
}