I am creating models, and in the base class for models, I need a static method that returns an instance of the class that the method was called on. As an example, when Person.getInstance() is called, I want new Person() to be returned.
The problem for me is to find out what class the function was called on. Any suggestions?
/** * The base class for models */ public class BaseModel { public static BaseModel getInstance() { // I want this method to return an instance of the class that it was // called on, like Person or Vehicle. } } public class Person extends BaseModel { public String name; public Person() { this.name = "John Doe"; } }