Wednesday, 23 November 2016

weakhashmap

MyKey key=new MyKey(3);
MyValue value=new MyValue(3);
HashMap hashMap=new HashMap<>(); 
hashMap.put(key, value); 
key=null; 
System.gc(); 
System.out.println(hashMap.get(new MyKey(3))); 


 key=new MyKey(3); 
WeakHashMap hashMap2=new WeakHashMap<>(); 
hashMap2.put(key, value); 
key=null; 
TimeUnit.SECONDS.sleep(5); 
System.gc(); 
System.out.println(hashMap2.get(new MyKey(3)));

MyValue [v=3]
null

use of xor

No comments:

Post a Comment