我们有一个包含两个方法的类消费接口,另一个类需要第一个类不想使用的第三个方法。如何实施。 [英] We have one class consuming interface containing two methods, another class wants third method which first class don’t want to use. How to implement.
本文介绍了我们有一个包含两个方法的类消费接口,另一个类需要第一个类不想使用的第三个方法。如何实施。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有一个类(X)消耗Interface(I)在Interface中包含两个方法,另一个类(Y)实现相同的接口,想要第一个类不想使用的第三个方法。如何实施。
我尝试过:
我们有一个类(X)消耗Interface(I)在Interface中包含两个方法,另一个类(Y)实现相同的接口,想要第一个类不想使用的第三个方法。如何实现。
We have one class(X) consuming Interface(I) containing two methods in Interface, another class(Y) implementing same interface, wants third method which first class don’t want to use. How to implement.
What I have tried:
We have one class(X) consuming Interface(I) containing two methods in Interface, another class(Y) implementing same interface, wants third method which first class don’t want to use. How to implement.
推荐答案
你不能:接口的所有方法都必须在包括它的所有类中实现;你不能挑选实施哪些方法。
这并不意味着该方法必须做任何有用的事情:只要它具有正确的签名(即它接受正确的参数并返回正确的值类型)接口很高兴。
You can't: all methods of an Interface must be implemented in all classes including it; you can't "pick and choose" which methods to implement.
That doesn't mean that the method has to do anything useful: provided it has the right signature (i.e. it accepts the right parameters and returns the right type of value) the Interface is happy.
这篇关于我们有一个包含两个方法的类消费接口,另一个类需要第一个类不想使用的第三个方法。如何实施。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文