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

Inference regression with JDK 8 and -source 7

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 8
    • tools

      This program doesn't compile when source is set to a value other than 8 (the example is a bit more verbose than necessary, to get better output):

      interface Bar<X extends Bar<X>> { }

      class Test {
          <A extends Bar<A>> void test() {
              A result = m();
          }

      <B extends Bar<B>> B m() {
              return null;
          }
      }

      Error:

      /opt/JDK/8/re/b40/bin/javac -source 7 Main.java
      Main.java:7: error: incompatible types: inferred type does not conform to upper bound(s)
              A result = m();
                          ^
          inferred: B
          upper bound(s): Bar<B>,A
        where B,A are type-variables:
          B extends A
          A extends Bar<A> declared in method <A>test()
      1 error

      Compiling w/o the -source flag, or with a JDK 7 compiler works w/o issues.

            dlsmith Dan Smith
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: