Skip to main content

Practice ยท 2 of 3

The copy API, typed correctly

1. static <T> void copy(List<? extends T> src, List<? super T> dst) โ€” append every element of src to the end of dst. Must NOT disturb existing dst content. 2. static void swap(List<?> list, int i, int j) โ€” swap two elements. Because ? cannot be written to, implement via a private generic capture helper static <E> void swapHelper(List<E> list, int i, int j) and call it. Both must compile with exactly these signatures (wildcards in the public API).

Difficulty: advanced

Back to lesson: Practice: Type-system drills