This is bizarre... I thought every object in java had Object as an ancestor.
I have a ClassA
that extends my ClassB
and implements Runnable
.
After creating ClassA
I cannot cast it to an Object
.
Assume getClassA
returns a ClassA
instance.
I am doing
Object obj = getClassA();
I also tried
Object obj = (Object) getClassA();
I get an incompatible types compile error: found Class, required Object.
What's the deal with that? I thought all objects could be cast to Object.
Edit: I assume it has something to do with the fact that ClassA implements Runnable, but I am not sure and need an explanation.
Edit2: Changing getClassA() to return an Object allows the program to compile.
Edit3: Importing the package that contained ClassB fixed the problem. Class B was defined in a different jar. ClassA was defined in another jar that referenced the jar containing ClassB.