import java.util.*; public class Bounds { static class AlternateSet{ HashSet a = new HashSet<>(); // Adds all elements in c to this set // (that are not already present) // Slide 37 // void addAll(Set c){ // a.addAll(c); // } // Slide 38 // void addAll(Collection c){ // a.addAll(c); // } // Slide 39 void addAll(Collection c){ a.addAll(c); } } // Slide 41 static class UtilsGenerified { static double sumList(List lst) { double result = 0.0; for (Number n : lst) { // T also works result += n.doubleValue(); } return result; } // Slide 42 // static void copyTo(List dst, List src) { // for (T t : src) // dst.add(t); // } static void copyTo(List dst, List src) { for (T2 t : src) dst.add(t); } } public static void main(String[] args){ // Slide 39 ArrayList doublesList = new ArrayList<>(Arrays.asList(1.0,2.0)); ArrayList intList = new ArrayList<>(Arrays.asList(1, 2)); HashSet doubleSet = new HashSet<>(doublesList); AlternateSet newDoubles = new AlternateSet<>(); newDoubles.addAll(doublesList); newDoubles.addAll(doubleSet); // newDoubles.addAll(intList); AlternateSet newNumbers = new AlternateSet<>(); newNumbers.addAll(doublesList); newNumbers.addAll(doubleSet); newNumbers.addAll(intList); } }