Java:你怎么称这种多重继承歧义? [英] Java: how do you call this multiple inheritance ambiguity?
问题描述
这是一个在Java中使用多个接口继承的示例,并且存在一个问题。
Here's an example using multiple interface inheritance in Java and there's an issue.
请注意,我完全知道为什么会出现问题,这不是我的问题所在。 。问题是关于如何命名这个特定的多接口继承歧义,如果它有一个名称。
Note that I fully know why there's an issue and this is not the point of my question. The question is about how you name this particular multiple interface inheritance ambiguity, if there's a name for it.
例如,在C ++中,当你使用多个时产生的歧义实现继承并且无法确定使用哪个重写方法称为钻石问题:
For example, in C++, the ambiguity that arises when you use multiple implementation inheritance and cannot determine which overridden method to use is called the "diamond problem":
http://en.wikipedia.org/wiki/Diamond_problem
现在又一次,我知道这不是同样的问题:这不是重点。关键是在之前的案例中已经创造了一个名称。
Now once again, I know this is not the same problem here: that's not the point. The point is that a name has been coined in that previous case.
我想知道我将要描述的问题是否存在名称。
And I'd like to know if a name exists for the issue I'm about to describe.
这是另一种多重继承的示例,其中一个接口继承自另外两个具有不兼容方法返回类型的接口:
Here's an example of another kind of multiple inheritance, where one interface inherits from two other interfaces that have an incompatible method return type:
interface A {
void a();
Integer c();
}
interface B {
void b();
Long c();
}
interface MI extends A, B {...}
(使用'extends'关键字注意工作中的多个接口继承)
(notice multiple interface inheritance at work using the 'extends' keyword)
你不能这样做,因为:
类型A和B不兼容;两个
定义c()但是不相关的返回
类型
types A and B are incompatible; both define c() but with unrelated return type
是否有一个名称被用来描述这种情况?
Has a name been coined to describe that situation?
推荐答案
我不确定它是否有特定名称,或者至少看起来不是很好常用的。它只是接口方法隐式映射到类方法的问题;如果你可能只有返回类型不同的重载,那么也没有问题。因此,它归结为签名/重载/隐式方法映射问题。
I'm not sure there is a specific name for it, or at least it doesn't seem to be very commonly used. It's "just" a problem of the implicit mapping of interface methods to class methods; if you could have overloads which differ in return types only, there would be no problem either. So it comes down to an signature/overloading/implicit method mapping problem.
在Thinking in Java在线书籍中,也没有名称。
http://www.linuxtopia.org/online_books/programming_books/ thinking_in_java / TIJ310_001.htm
In the "Thinking in Java" online book, there isn't a name for it either. http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ310_001.htm
只是旁注,C#允许显式接口实现,解决了这个问题。
Just a side-note, C# allows explicit interface implementations, which addresses this problem.
这篇关于Java:你怎么称这种多重继承歧义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!