-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.0.2
-
sparc
-
generic
Name: ###@###.### Date: 09/04/96
Java language specification (8.1.2.1 abstract Classes) says:
"It is a compile-time error to declare an abstract class type such that
it is not possible to create a subclass that implements all of its
abstract methods. This situation can occur if the class would have as
members two abstract methods that have the same method signature
(8.4.2) but different return types. "
See also (8.4.6.4 Inheriting Methods with the Same Signature):
"If none of the inherited methods is not abstract, then the class is
necessarily an abstract class and is considered to inherit all the
abstract methods.
- A compile-time error occurs if, for any two such inherited
methods, either they have different return types or one has a
return type and the other is void."
However Java compiler doesn't recognize this situation and doesn't report error
(but it must) in the following particular case:
- a class has two abstract methods that have the same method signature
but different return types,
- and one of the methods is inherited from interface,
- and there are no concrete subclass definition.
See example below:
> javac clss01003.java
>
---------------------------clss01003.java-----------------------
interface iclss01003_2 {
abstract void foo(int par);
}
abstract class clss01003_b {
abstract int foo(int par);
}
abstract class clss01003_a extends clss01003_b implements iclss01003_2 {
}
----------------------------------------------------------------
======================================================================
- duplicates
-
JDK-4041948 Javac allows interfaces to inherit methods with inconsistent signatures.
- Closed