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

Cast from a raw type with non-generic supertype to a raw type fails unexpectedly

    Details

    • Subcomponent:
    • Resolved In Build:
      b27
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description

      interface Super<P> {}
      class Y<A> implements Super<Integer>{}
      interface X<A> extends Super<Double>{}
      class S<L> extends Y<Object> {}
      interface T<L> extends X<Object>{}

      public class Test{
          public static void main(String argv[]) {
              S s = null; // same if I use S<Byte>
              T t = null; // same if I use T<Byte>
              t = (T) s;
          }
      }

      This should not fail. T is raw in the cast.
      Compile-time error:

      interface Super<P> {}
      class Y<A> implements Super<Integer>{}
      interface X<A> extends Super<Double>{}
      class S extends Y<Object> {}
      interface T extends X<Object>{}

      public class Test{
          public static void main(String argv[]) {
              S s = null;
              T t = null;
              t = (T) s;
          }
      }

      Yes. Distinct supertypes: Super<Integer> and Super<Double>.
      Compile-time error:

      interface Super<P> {}
      class Y implements Super<Integer>{}
      interface X extends Super<Double>{}
      class S<L> extends Y {}
      interface T<L> extends X{}

      public class Test{
          public static void main(String argv[]) {
              S s = null; // also if I use S<Byte>
              T t = null; // also if I use T<Byte>
              t = (T) s;
          }
      }

      Looks like a bug. The program should compile because you cast to the
      *raw* type T.
      interface Super<P> {}
      class Y<A> implements Super<Integer>{}
      interface X<A> extends Super<Double>{}
      class S extends Y {}
      interface T extends X{}

      public class Test{

          public static void main(String argv[]) {
              S s = null;
              T t = null;
              t = (T) s;
          }
      }
      interface Super<P> {}
      class Y implements Super<Integer>{}
      interface X extends Super<Double>{}
      class S extends Y {}
      interface T extends X{}

      public class Test{
          public static void main(String argv[]) {
              S s = null;
              T t = null;
              t = (T) s;
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                ahe Peter Ahe
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: