Created
August 2, 2016 11:50
-
-
Save Glorp/f8399fca93afc7e9993d4d7b1c8d3f21 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
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
public class Mutability { | |
public static void main(String[] args) { | |
ArrayList<String> l1 = new ArrayList<>(); | |
l1.add("foo"); | |
l1.add("bar"); | |
ArrayList<String> l2 = new ArrayList<>(); | |
l2.add("foo"); | |
l2.add("bar"); | |
Set<List<String>> s = new HashSet<>(); | |
s.add(l1); | |
System.out.printf("s.size() = %s; s.contains(l1) = %s; s.contains(l2) = %s;\n", s.size(), s.contains(l1), s.contains(l2)); | |
l1.add("quux"); | |
System.out.printf("s.size() = %s; s.contains(l1) = %s; s.contains(l2) = %s;\n", s.size(), s.contains(l1), s.contains(l2)); | |
} | |
} |
Author
Glorp
commented
Aug 2, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment