Created
July 1, 2015 10:18
-
-
Save seanjreilly/a646e53ac93925a06680 to your computer and use it in GitHub Desktop.
Pattern for ensuring that an optional collection passed into an argument is immutable
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
import java.util.Optional; | |
import java.util.LinkedHashSet; | |
import java,util.Collections; | |
public final class Foo { | |
private final Optional<Set<String>> args; | |
public Foo(Optional<Set<String>> args) { | |
this.args = args.map(LinkedHashSet::new).map(Collections::unmodifiableSet); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment