当我在 Eclipse 中编译以下代码时 - 没有任何错误。
只有一个警告:
SomeDerivedAbstractClass is a raw type. References to generic type SomeDerivedAbstractClass should be parameterized
我在最新的 Eclipse Indigo(3.7.1) 中测试了这段代码。
但是当我试图用javac编译这段代码时出现了以下错误:
SomeConcreateClass.java:1: ISomeBaseInterface cannot be inherited with different arguments: <java.lang.Object> and <>
public class SomeConcreateClass
^
1 error
我使用 Java 5 和 Java 6 编译了这段代码。在这两种情况下都有错误。
这段代码有什么问题?
public class SomeConcreateClass
extends SomeDerivedClass
implements ISomeInterface
{}
class SomeDerivedClass<T>
extends SomeAbstractClass<Object>
implements ISomeInterface
{
}
abstract class SomeAbstractClass<T>
implements ISomeBaseInterface<T>
{
}
interface ISomeInterface extends ISomeBaseInterface<Object>
{}
interface ISomeBaseInterface<T>
{
}
但是下面的代码既不能在 Eclipse 中编译也不能通过 javac 编译:
public class SomeConcreateClass
extends SomeAbstractClass
implements ISomeInterface
{}
abstract class SomeAbstractClass<T>
implements ISomeBaseInterface<Object>
{}
interface ISomeInterface extends ISomeBaseInterface<Object>
{}
interface ISomeBaseInterface<T>
{}
javac:
SomeConcreateClass.java:1: ISomeBaseInterface cannot be inherited with different arguments: and <> public class SomeConcreateClass ^ 1 error
eclipse :
The interface ISomeBaseInterface cannot be implemented more than once with different arguments: ISomeBaseInterface and ISomeBaseInterface
那么 - 这是 Eclipse 中的错误吗?
是不是和https://bugs.eclipse.org/bugs/show_bug.cgi?id=81824一样的bug ?
更多更新:
此代码通过 javac 和 Eclipse 编译都没有错误:
public class SomeConcreateClass
extends SomeDerivedClass
implements ISomeInterface
{}
class SomeDerivedClass
extends SomeAbstractClass<Object>
implements ISomeInterface
{}
abstract class SomeAbstractClass<T>
implements ISomeBaseInterface<T>
{}
interface ISomeInterface extends ISomeBaseInterface<Object>
{}
interface ISomeBaseInterface<T>
{}
只有一个区别:SomeDerivedClass 没有参数化。
我不明白这对 ISomeBaseInterface 有何影响。
还有一个更新:
我检查了 IntellijIDEA 中第一个示例的代码 - 这个 IDE 显示错误。
但我认为它使用与 Eclipse 不同的编译方法。
最佳答案
Something<> 与 Something
SomeAbstractClass
我想你可能想使用 SomeDerivedAbstractClass>。
关于java - ISomeBaseInterface 不能用不同的参数继承 : <java. lang.Object> 和 <>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8433025/