“Could not resolve matching constructor” error when passing in constructor-arg for child class

后端 未结 3 1963
别跟我提以往
别跟我提以往 2021-01-17 02:33

I have the following classes:

public abstract class ParentClass
{
    public ParentClass()
    {
        throw new RuntimeException(\"An ID must be specified         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-17 03:10

    calling an inherited constructor to instantiate the class?

    Constructors are never inherited, and it doesn't really make sense. A constructor just initializes the state in that particular class. You can't expect a constructor of Parent to initialize the state of Child class. That's the job of constructor in Child class only.

    So, no you can't do what you are trying to do. And that's not the issue with Spring. That's pretty much fundamental.

提交回复
热议问题