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

Code compiles in java8 but not in java9 : "incompatible types: java.lang.Object cannot be converted ..."

    Details

    • Subcomponent:
    • Introduced In Build:
      b94
    • Introduced In Version:
      9
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "9.0.4"
      Java(TM) SE Runtime Environment (build 9.0.4+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Windows 10 Enterprise 64-bit

      A DESCRIPTION OF THE PROBLEM :
      The attached code does not compile in java 9, intellij idea do not suggest any problems with it. To make it compiling one must do a implicit cast or assign intermediate result to a typed variable.


      REGRESSION. Last worked in version 8u161

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile the attached code in java 9

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      it compiles since it is compilable in java 8 ant development tool (intellij idea) do not report any problems with the code.
      ACTUAL -
      Error:(20, 113) java: incompatible types: java.lang.Object cannot be converted to /package name here/.Base

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Error:(20, 113) java: incompatible types: java.lang.Object cannot be converted to /package name here/.Base

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class StreamOfStreams {


        public static void main(String[] args) {
          Helper h = new Helper();
          Stream.of(h.get(A.class).stream(), h.get(B.class).stream()).flatMap(Function.identity()).filter(r -> h.test(r));
        }
      }

      class Base {
      }

      class A extends Base {
      }

      class B extends Base {
      }

      class Helper {
        public <T extends Base> Set<T> get(final Class<T> clazz) {
          return new HashSet<>();
        }

        public boolean test(Base b) {
          return true;
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      public class StreamOfStreams {


        public static void main(String[] args) {
          Helper h = new Helper();
          Stream.of(h.get(A.class).stream(), h.get(B.class).stream()).flatMap(Function.identity()).filter(r -> h.test((Base)r));
        }
      }

      class Base {
      }

      class A extends Base {
      }

      class B extends Base {
      }

      class Helper {
        public <T extends Base> Set<T> get(final Class<T> clazz) {
          return new HashSet<>();
        }

        public boolean test(Base b) {
          return true;
        }
      }


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: