Matters needing attention when creating subclasses through reflection in abstract parent classes

Issues to be aware of when creating instances of subclasses through reflection in abstract classes

1. An abstract class cannot have an abstract constructor

2. An abstract class cannot create new objects, only objects of subclasses can be created, and the constructor of an abstract class cannot be obtained through reflection to create objects

3. The constructor of the subclass and the parent class is not an inheritance relationship, but a calling relationship, that is, if the subclass wants to implement the constructor with parameters of the parent class, the subclass needs to rewrite the constructor of the parent class with parameters, and then pass the super keyword. The constructor with the same parameters of the parent class is called, and then the constructor with parameters of the subclass can be created by reflection in the parent class. Otherwise, if there is a constructor with parameters in the parent class, but the subclass does not, a parameter not found error will be reported when an object of the subclass is created through this constructor with parameters

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324597859&siteId=291194637