When I compile following code in Eclipse – there are no any errors.
There is only one warning:
SomeDerivedAbstractClass is a raw type. References to generic type
SomeDerivedAbstractClass should be parameterized
I tested this code in the newest Eclipse Indigo(3.7.1).
But there is following error when I tried to compile this code by javac:
SomeConcreateClass.java:1: ISomeBaseInterface cannot be inherited with different arguments: <java.lang.Object> and <>
public class SomeConcreateClass
^
1 error
I compiled this code suing Java 5 and Java 6. In both cases there is error.
What is wrong in this code?
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>
{
}
But following code does not compile either in Eclipse or by 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
So – is it a bug in Eclipse?
Is it the same bug as https://bugs.eclipse.org/bugs/show_bug.cgi?id=81824 ?
ONE MORE UPDATE:
This code compiles without errors both by javac and 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>
{}
There is only one difference: SomeDerivedClass is not parameterized.
I do not understand how does this influence on ISomeBaseInterface.
AND ONE MORE UPDATE:
I checked code from the first example in IntellijIDEA – this IDE shows error.
But I think it uses different approach for compilation than Eclipse.
Something<> is NOT the same as Something<Object> (even though it might seem like that is reasonable).
SomeAbstractClass<T> implements ISomeBaseInterface<T>, and SomeAbstractClass<> implements ISomeBaseInterface<> So when you use SomeDerivedAbstractClass<> (in SomeConcreateClass), you’re asking the class to implement both ISomeConcreateInterface (that is, ISomeBaseInterface<Object>) and ISomeBaseInterface<> at the same time, which it cannot do.
You might want to use SomeDerivedAbstractClass<?>, I think.