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{
}
Any suggestions?
Thanks in advance!