对Java语言的思考(1)接口

原文地址:https://www.cnblogs.com/huanghezhao/p/11257455.html

问题:如果有两个接口,他们恰好声明了同名方法,而这两个方法的参数相同,但返回类型不同。如何写一个类,同时实现这两个接口?

答:没法实现。这篇文章[1]已经给出证明了,就不再累述。

C#就很好地解决了这个问题。C#允许一个类在实现接口时,显式地标注实现的是哪个接口的哪个方法[2]。

参考资料

  1. https://www.geeksforgeeks.org/two-interfaces-methods-signature-different-return-types/
  2. https://www.geeksforgeeks.org/c-sharp-how-to-implement-multiple-interfaces-having-same-method-name/

猜你喜欢

转载自www.cnblogs.com/huanghezhao/p/11257455.html