This question is very similar to the questions in can't cast to implemented interface. Classloader issues - How to determine which library versions (jar-files) are loaded
I have a class Apple which implements Beet. Beet extends Carrot
Carrot c= x.getCarrot();
c.getClass() //returns Apple
c.getClass().getInterfaces()[0] //returns Beet.
I want to access methods inside Apple. So what I did was cast c to Beet.
Beet b=(Beet)c;
At this point I am receiving a ClassCastException
. I think this is due to the ClassLoader problem discussed in the above links.
But I don't understand how to fix this. I don't know OSGi much and I don't know how to refer bundles. Can someone explain to me how to fix this problem and a good reference point.