intermediate.AboutAutoboxing Maven / Gradle / Ivy
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 list = new ArrayList();
list.add(0, new Integer(42));
assertEquals(list.get(0), __);
}
@Koan
public void addPrimitivesToCollectionWithAutoBoxing() {
List list = new ArrayList();
list.add(0, 42);
assertEquals(list.get(0), __);
}
@Koan
public void migrateYourExistingCodeToAutoBoxingWithoutFear() {
List list = new ArrayList();
list.add(0, new Integer(42));
assertEquals(list.get(0), __);
list.add(1, 84);
assertEquals(list.get(1), __);
}
@Koan
public void allPrimitivesCanBeAutoboxed() {
List doubleList = new ArrayList();
doubleList.add(0, new Double(42));
assertEquals(doubleList.get(0), __);
List longList = new ArrayList();
longList.add(0, new Long(42));
assertEquals(longList.get(0), __);
List characterList = new ArrayList();
characterList.add(0, new Character('z'));
assertEquals(characterList.get(0), __);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy