本文介绍了如果接口没有实现类,如何使用接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-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
如果没有实现类,请告诉我如何使用界面? 例如,考虑一下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子句中最终使用此接口时才能用于某些真正的软件产品。
更多推荐
如果接口没有实现类,如何使用接口
发布评论