If a method returns an interface, what does it mean?

后端 未结 4 1350
眼角桃花
眼角桃花 2021-01-18 11:38

I see many methods that specify an interface as return value. Is my thought true that it means: my method can return every class type that inherits from that interface? if n

4条回答
  •  无人及你
    2021-01-18 12:21

    Yes, that method might return an object of any type that implements that interface.

    But, to use the non-interface members of a particular type, you'll need to cast it to that type.

提交回复
热议问题