Name: swC45995 Date: 01/28/97
The following assertion do not holds:
The detailed rules for compile-time correctness checking of a casting
conversion of a value of compile-time reference type S (source) to a
compile-time reference type T (target) are as follows:
...
If S is an interface type:
...
If T is an interface type and if T and S contain methods with the same
signature but different return types, then a compile-time error occurs.
(JLS, 5.5 Casting Conversion)
Thus, compilation of the source file:
interface SomeInterface
{
int square(int i);
}
interface AnotherInterface
{
long square(int i);
}
public class test
{
static void check(AnotherInterface v)
{
SomeInterface u = (SomeInterface) v;
}
public static void main(String argv[])
{
AnotherInterface v = null;
check(v);
}
}
ends without detecting any errors though SomeInterface and AnotherInterface
contain the method square with the same signature but different return types
(int and long accordingly)
======================================================================
- duplicates
-
JDK-4072429 Method compatibility not checked during cast conversion
- Closed