Passing different type than parameter type

前端 未结 4 380
庸人自扰
庸人自扰 2021-01-07 08:50

If I would have a variable a declared by A a and a method m with void m(B b). Is there any way that calling m(a)

4条回答
  •  攒了一身酷
    2021-01-07 09:20

    If A extends B, it can be passed as argument to that function. If not and A contains values suitable for B you have to create an instance of B and fill it with the required values of the instance of A.

提交回复
热议问题