dimanche 25 février 2018

Create a concrete object in a abstract class by using reflect methods

Suppose I have an abstract class called Model with the following static method:

 
public abstract class Model {
    ...
    public static List<Model> all() {
       ...
    }
    ...
}

And a concrete class the extends it:

public class Person exends Model {
...
}

So, is it possible to, using a static context, Person.all() return a list of Person and not of Model?

You know, by using a Template, or reflect methods such as getClass().getClassName() and getClass().getDeclaredMethod() and etc.

I am asking that because I have seen that in a PHP library and I am creating a similar library in java.





Aucun commentaire:

Enregistrer un commentaire