Java - getConstructor() ?

Posted by msr on Stack Overflow See other posts from Stack Overflow or by msr
Published on 2010-04-23T23:53:09Z Indexed on 2010/04/23 23:53 UTC
Read the original article Hit count: 337

Filed under:
|
|

Hello,

I wrote the question as a comment in the code, I think its easier to understand this way.

public class Xpto{
    protected AbstractClass x;

    public void foo(){

       // AbstractClass y = new ????? Car or Person ?????

       /* here I need a new object of this.x's type (which could be Car or Person)
          I know that with x.getClass() I get the x's Class (which will be Car or 
          Person), however Im wondering how can I get and USE it's contructor */

       // ... more operations (which depend on y's type)
    }

}

public abstract class AbstractClass {
}

public class Car extends AbstractClass{
}

public class Person extends AbstractClass{
}

© Stack Overflow or respective owner

Related posts about java

Related posts about getconstructor