Re: How to get the runtime class?




"Fredy" <a@xxx> wrote in message news:d4u0t9$jcu$1@xxxxxxxxxxxxxxxxxx
> I have 2 classes
>
> abstract public class foo {
>
>
> public void bar() {
>
> // i want a Class object of "this"
>
> Class c = this.getClass(); // here i get a class of type foo, even if
> the runtime class is type foo2

this.getClass() returns the actual class of the object, not simply the
class of the current method. If you're getting "foo" instead of "foo2" for
an object that is of class "foo2" you have some other problem. Can you show
a short, complete example of code where this happens?

> }
> }
>
> public class foo2 extends foo {
>
> ...
> }
>
> with other words, how to get the children object from the parent object?
getChildren () ? Your question doesn't make any sense in the context of
class types. Do you mean how can you get all the instances of a particular
class or all the subclasses of a particular class? You'll need to explain
what you want a little more.

Cheers,
Matt Humphrey matth@xxxxxxxxxxxxxx http://www.iviz.com/


.



Relevant Pages