Created
July 8, 2015 14:52
-
-
Save kirkbackus/e96ad7df18a80190e994 to your computer and use it in GitHub Desktop.
Testing the shallow copy of an object to see if the second map keeps the original objects around after the first map is cleared. Turns out, the second map does in fact keep the objects around!
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.Map; | |
import java.util.HashMap; | |
public class TestShallowCopy { | |
public static void main(String[] args) { | |
Map<String, Integer> a = new HashMap<String, Integer>(); | |
a.put("TEST", 1); | |
Map<String, Integer> b = new HashMap<String, Integer>(a); | |
a.clear(); | |
System.out.println("TEST: "+b.get("TEST")); | |
System.out.println("A-size: "+a.size()); | |
System.out.println("B-size: "+b.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment