Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extended a class, getting a class cast error

807600Nov 14 2007 — edited Nov 16 2007
Hi all,

I'm writing a program that uses a closed-source jar in its library (with permission, of course).

One of the classes in that jar wasn't working as I wanted it to, so I extended the class and overwrote one of its methods. So, when using the class, instead of calling
ThirdPartyClass obj = new ThirdPartyClass();
I could use
MyThirdPartyClass obj = new MyThirdPartyClass();
This seems to work, until a certain line of their code throws a class cast exception:
java.lang.ClassCastException: org.thirdparty.ThirdPartyClass$2
	at org.thirdparty.Event.findTop(Event.java:279)
	at org.thirdparty.ThreadUtils$4.run(ThreadUtils.java:86
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    ....
Why does this occur? Surely, since MyThirdPartyClass is a child of ThirdPartyClass, anything that expects a ThirdPartyClass shouldn't have any problem, right? Or do I have that backwards? And if so, is there anything I can do to fix the problem?

Thanks!
Sam
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 14 2007
Added on Nov 14 2007
24 comments
411 views