Last active
August 29, 2015 13:57
-
-
Save chris-martin/9837923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package foo; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.Optional; | |
public class OptionalTest { | |
static class Foo<T> { | |
Collection<? extends Optional<? extends T>> source; | |
Collection<? super Optional<? extends T>> target; | |
void copy() { | |
target.addAll(source); | |
} | |
} | |
public static void main(String[] args) { | |
Foo<Number> foo = new Foo<>(); | |
List<Optional<? extends Integer>> a = new ArrayList<>(); | |
a.add(Optional.of(1)); | |
a.add(Optional.<Integer>empty()); | |
a.add(Optional.of(3)); | |
List<Optional<? extends Object>> b = new ArrayList<>(); | |
b.add(Optional.of("A")); | |
b.add(Optional.empty()); | |
foo.source = a; | |
foo.target = b; | |
foo.copy(); | |
System.out.println(b); | |
// [Optional[A], Optional.empty, Optional[1], Optional.empty, Optional[3]] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment