-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutAutoboxing.java
More file actions
52 lines (40 loc) · 1.41 KB
/
AboutAutoboxing.java
File metadata and controls
52 lines (40 loc) · 1.41 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package intermediate;
import com.sandwich.koan.Koan;
import java.util.ArrayList;
import java.util.List;
import static com.sandwich.koan.constant.KoanConstants.__;
import static com.sandwich.util.Assert.assertEquals;
public class AboutAutoboxing {
@Koan
public void addPrimitivesToCollection() {
List<Integer> list = new ArrayList<Integer>();
list.add(0, new Integer(42));
assertEquals(list.get(0), 42);
}
@Koan
public void addPrimitivesToCollectionWithAutoBoxing() {
List<Integer> list = new ArrayList<Integer>();
list.add(0, 42);
assertEquals(list.get(0), 42);
}
@Koan
public void migrateYourExistingCodeToAutoBoxingWithoutFear() {
List<Integer> list = new ArrayList<Integer>();
list.add(0, new Integer(42));
assertEquals(list.get(0), 42);
list.add(1, 84);
assertEquals(list.get(1), 84);
}
@Koan
public void allPrimitivesCanBeAutoboxed() {
List<Double> doubleList = new ArrayList<Double>();
doubleList.add(0, new Double(42));
assertEquals(doubleList.get(0), 42.0);
List<Long> longList = new ArrayList<Long>();
longList.add(0, new Long(42));
assertEquals(longList.get(0),42l);
List<Character> characterList = new ArrayList<Character>();
characterList.add(0, new Character('z'));
assertEquals(characterList.get(0), 'z');
}
}