aspose file tools
The moose likes Java in General and the fly likes java.lang.ClassCastException in Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "java.lang.ClassCastException in Collections" Watch "java.lang.ClassCastException in Collections" New topic
Author

java.lang.ClassCastException in Collections

Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Any reasonable sized application may have ten thousand branch points, so the number of execution paths through an application can be a very large.

Testing all those paths is a difficult task. (ahem.)

As a design decision, I left

as


Thinking the compiler would not even accept it, and if it did, it would fail on the first test efforts at this point, which it did.

Accomplished authors do it like this:


This compare is so much on the critical path that I wanted to break it on the first run in hopes of being *absolutely* sure this is the only way, the One True Way and,

The Official Documented: There is no Other Way way.

Many of the Collections require a compareTo() method to do their work.

Stack trace was of limited but real value, static constructor for class Alice prints:

"Globals! (Oh, the Horror) - Boris Alexeev"

Which showed up in the run log, so it's likely the ClassCastException did in fact occur during a Collections' attempt to do exactly what it said it would do.

I just need to avoid

later.

No room for that where this is going.

They don't use ropes to hang.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi cowboys,


I do not know who Boris Alexeev is but
the answer depends on whether you use generics or not.

When your class implements Comparable,
compareTo(Object boris) { }
would be the only way to override compareTo.


But when your class implements Comparable <Alice>
it should be
compareTo (Alice alexeev) { }




Frontal lobals, oh the horror!

Yours,
Bu.


all events occur in real time
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
I have jdk 1.2 or 1.3 or something, it does not have templated instantiations.

I.O.W. the slicing problem does not exist in Java ... so in that the only way the compiler has to separate overload signatures is by paramater list, the compiler authors have made arrangements to prevent losing the original class's definition.
[ May 20, 2007: Message edited by: Nicholas Jordan ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: java.lang.ClassCastException in Collections
 
Similar Threads
Which Dilbert character would you hire?
compareTo method
problem with compareTo method
Packaging, naming and directory structure.
Comparable Vs. Comparator.