• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCastException

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here's the scene ........ i've gotta function which i need to call whose signature goes like this


and is inside a class named AdvertisementFactory.

now ive got a class called CodatAdv which has got a public static Inner class named Instantiator which implements the original AdvertisementFactory.Instantiator and has all the methods of that particular interface(AdvertisementFactory.Instantiator)

But when i call the above static method with the following parameters



i get a classcastexception at runtime....... can someone out here tell me where i'm going wrong coz as far as i know a super-interface can always point to a sub-interface of the same class.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had some trouble following you, but as far as I can tell, you're describing something like this (with a few names shortened)...

This compiles and runs fine for me.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that really a beginner's question?

Whenever you get an Exception you need to look at its stack trace, and find out where it occurred. That should give you a hint what to do to sort it out.
 
Crusading Chameleon likes the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic