-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoxDemo.java
32 lines (29 loc) · 945 Bytes
/
BoxDemo.java
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
public class BoxDemo{
public static <U> void addBox(
U u,
java.util.List<Box<U>> boxes
){
Box<U> box = new Box<>();
box.set(u);
boxes.add(box);
}
public static <U> void outputBoxes(
java.util.List<Box<U>> boxes
){
int counter = 0;
for(Box<U> box : boxes){
U boxContents = box.get();
System.out.println("Box #" + counter + " contain [" +
boxContents.toString() + ']');
counter++;
}
}
public static void main(String[] args){
java.util.ArrayList<Box<Integer>> listOfIntegerBoxes =
new java.util.ArrayList<>();
BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);
BoxDemo.addBox(Integer.valueOf(20), listOfIntegerBoxes);
BoxDemo.addBox(Integer.valueOf(30), listOfIntegerBoxes);
BoxDemo.outputBoxes(listOfIntegerBoxes);
}
}