Hi,
I just ran in an unexpected problem. Consider the code below:
import java.awt.geom.*;
//import java.awt.geom.Point2D;
//import java.awt.geom.Point2D.Double;
. . .
public static final Comparator X_VALUE_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
java.awt.geom.Point2D.Double obj1 = (java.awt.geom.Point2D.Double)o1;
java.awt.geom.Point2D.Double obj2 = (java.awt.geom.Point2D.Double)o2; // ClassCastException
double diff = obj1.getX() - obj2.getX();
return((int)Math.signum(diff));
//return 0;
}
};
This is a fragment from a class that imports the mentioned packages and contains this comparator. The second cast (with obj2) throws a ClassCastException, because he tries to cast to java.lang.Double. Surprisingly to me, the line before is no problem. If I comment out the line with obj2 and the following dependent ones, it executes with no problems.
Is this a bug? It seems to be similar to
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4198349
but the workaround doesn't work for me. As you see, I'm using the full classpath and have also tried several other combinations.
I am using JDK 1.5 on Mac OS X.