Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4028359

inability to detect invalid cast between interfaces

XMLWordPrintable

    • 1.2beta2
    • x86, sparc
    • solaris_2.4, windows_95
    • Not verified



      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)

      ======================================================================

            tturnidgsunw Todd Turnidge (Inactive)
            wensunw Wen Wen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: