Problem: Cannot remove a key in HashMap
807569Aug 20 2006 — edited Aug 21 2006import java.awt.*;
import java.util.*;
import java.util.concurrent.*;
public class Test
{
public static void main( String[] args )
{
ConcurrentHashMap<Point,Integer> hashMap = new ConcurrentHashMap<Point,Integer>();
hashMap.put( new Point( 1, 2 ), 1 );
System.out.println( hashMap.containsKey( new Point( 1, 2 ) ) );
hashMap.remove( new Point( 1, 2 ) );
System.out.println( hashMap.containsKey( new Point( 1, 2 ) ) );
}
}
The above code work fine, but it fails when I changed "Point" into "IntegerPoint" (a class wrote by me). What's the problems?
import java.awt.*;
import java.util.*;
import java.util.concurrent.*;
public class Test
{
public static void main( String[] args )
{
ConcurrentHashMap<IntegerPoint,Integer> hashMap = new ConcurrentHashMap<IntegerPoint,Integer>();
hashMap.put( new IntegerPoint( 1, 2 ), 1 );
System.out.println( hashMap.containsKey( new IntegerPoint( 1, 2 ) ) );
hashMap.remove( new IntegerPoint( 1, 2 ) );
System.out.println( hashMap.containsKey( new IntegerPoint( 1, 2 ) ) );
}
}
Thank you very much!!!