如果没有正文,列表界面的添加方法如何工作? list接口的add方法在哪里定义? [英] How add method of list interface works when there is no body for it? Where is the add method of list interface defined?

查看:102
本文介绍了如果没有正文,列表界面的添加方法如何工作? list接口的add方法在哪里定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有正文,列表界面的添加方法是如何工作的?列表界面的添加方法在哪里定义?



我尝试过:



当没有正文时,如何添加列表界面的方法?列表接口的add方法在哪里定义?

how add method of list interface works when there is no body for it? where is the add method of list interface defined?

What I have tried:

how add method of list interface works when there is no body for it? where is the add method of list interface defined?

推荐答案

List是一个接口,而不是一个类,所以无法定义任何方法的主体 - 它定义了方法签名(方法必须输入和输出的内容)但不能定义代码的任何实现。当具体类添加接口时,它必须提供由接口定义定义的所有方法签名的实现。



同样,您不能创建实例接口 - 您只能创建实现接口的类的实例。但是你可以声明一个接口类型的变量,它可以包含实现该接口的任何对象。

当你尝试使用Add方法时,框架可以计算变量中的对象类型在运行时,并调用该类中定义的Add方法的相应版本。
List is an Interface, not a class, and so cannot define the body of any method - it defines the method signatures (what the methods must input and output) but cannot define any implementation of the code. When a concrete class adds an Interface, it must provide implementations of all the method signatures that were defined by the interface definition.

Similarly, you can't create an instance of an Interface - you can only create instances of the classes that implement the Interface. But you can declare a variable of the Interface type, and it can contain any object which implements that Interface.
When you try to use the Add method the framework works out what type of object is in the variable at run time, and calls the appropriate version of the Add method that was defined in that class.


这篇关于如果没有正文,列表界面的添加方法如何工作? list接口的add方法在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆