001package intermediate;
002
003import com.sandwich.koan.Koan;
004
005import java.util.ArrayList;
006import java.util.List;
007
008import static com.sandwich.koan.constant.KoanConstants.__;
009import static com.sandwich.util.Assert.assertEquals;
010
011public class AboutAutoboxing {
012
013    @Koan
014    public void addPrimitivesToCollection() {
015        List<Integer> list = new ArrayList<Integer>();
016        list.add(0, new Integer(42));
017        assertEquals(list.get(0), __);
018    }
019
020    @Koan
021    public void addPrimitivesToCollectionWithAutoBoxing() {
022        List<Integer> list = new ArrayList<Integer>();
023        list.add(0, 42);
024        assertEquals(list.get(0), __);
025    }
026
027    @Koan
028    public void migrateYourExistingCodeToAutoBoxingWithoutFear() {
029        List<Integer> list = new ArrayList<Integer>();
030        list.add(0, new Integer(42));
031        assertEquals(list.get(0), __);
032
033        list.add(1, 84);
034        assertEquals(list.get(1), __);
035    }
036
037    @Koan
038    public void allPrimitivesCanBeAutoboxed() {
039        List<Double> doubleList = new ArrayList<Double>();
040        doubleList.add(0, new Double(42));
041        assertEquals(doubleList.get(0), __);
042
043        List<Long> longList = new ArrayList<Long>();
044        longList.add(0, new Long(42));
045        assertEquals(longList.get(0), __);
046
047        List<Character> characterList = new ArrayList<Character>();
048        characterList.add(0, new Character('z'));
049        assertEquals(characterList.get(0), __);
050    }
051
052}