如果接口没有实现类,如何使用接口

编程入门 行业动态 更新时间:2024-10-19 06:17:38
本文介绍了如果接口没有实现类,如何使用接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果没有实现类,请告诉我如何使用界面? 例如,考虑一下Alert()界面Selenium jar。

Can you please let me know how to use an interface when there are no implement classes for it? For example, consider the Alert() interface in the Selenium jar.

推荐答案

某些类从未实现的接口完全没有意义。只有在有一个或多个实现时,才能以任何合理的方式使用接口。 想想看:没有实现的接口无法实例化为对象。 编译时类型的所有对象实际上总是具有一些不同的运行时类型,在绝对所有情况下,它都是实现所讨论的接口的类型。 如果你没有这样的实现,你只能以一些简单(并且完全无用)的方式使用接口类型,例如作为名称。您可以使用接口类型的名称,将其与某些字符串进行比较,使用反射来查找接口成员和这些成员的属性,等等。也许这可以作为编程练习有用,但只有在某些实现类型的某些implements子句中最终使用此接口时才能用于某些真正的软件产品。
-SA
The interfaces which are never implemented by some class make no sense at all. An interface can be used in any sensible way only if there is one or more implementation. Think about it: an interface without an implementation cannot be instantiated as an object. All objects which compile-time type is interface type in fact always have some different runtime type, which is, in absolutely all cases, is the type implementing the interface in question. If you don't have such implementation, you can use the interface type only in some trivial (and totally useless) way, for example as a name. You can take a name of interface type, compare it with some strings, use reflection to find out the interface members and properties of those members, and so on. Perhaps this can be useful as a programming exercise, but can only be useful for some real software product only if, ultimately, this interface is used in some "implements" clause of some implementing type.
—SA

更多推荐

如果接口没有实现类,如何使用接口

本文发布于:2023-11-09 20:52:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   如何使用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!