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

8.4.2: Define when bounds are the same



      It is not clear whether the following two signatures are "the same" or not:

      public static <T1 extends Cloneable & Iterable<String>> void foo(T1 x)
      public static <T2 extends Iterable<String> & Cloneable> void foo(T2 x)

      The condition that must be satisfied, from 8.4.2, is "the bounds of corresponding type variables are the same".

      This could be interpreted as having the same (unordered) set of bounds, or as having the same (ordered) list of bounds.

      javac prefers the set interpretation when determining overriding relationships, although it is internally inconsistent at times (see JDK-8013089, JDK-8013846).

      In fact, javac seems take this even a step further, by determining whether the intersection types suggested by the two lists of bounds are structurally equivalent -- e.g., T extends Object & Runnable & Cloneable == T extends Runnable & Cloneable.

      A risk of being to narrow in the definition of "the same" is that two declarations that "obviously" appear to be the same won't be related. A risk of being too broad is that erasure is no longer consistent between signatures that are "the same" (as in JDK-8013089).


          Issue Links



              • Assignee:
                dlsmith Dan Smith
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                3 Start watching this issue


                • Created: