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

15.12.2.5: Most specific for generic class constructors different than treatment of methods

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • tbd
    • 7, 8
    • specification

      Most specific testing for method invocations is the same whether an explicit type argument is provided or not. But most specific testing for constructors has different behavior, depending on whether diamond is used or not.

      class C<T> {
        C(T arg) {}
        C(String arg) {}
        static <X> C<X> make(X arg) {}
        static <X> C<X> make(String arg) {}
      }

      C.make("hi"); // make(String) is most specific
      C.<String>make("hi"); // make(String) is most specific
      new C<>("hi"); // C(String) is most specific
      new C<String>("hi"); // ERROR: ambiguous

      The difference is that, with an explicit class type argument, substitution happens before most-specific testing; while in every other case, the signatures are considered generically.

      This may be tolerable. But it's worth considering whether we can unify the behavior of explicitly-parameterized constructors and explicitly-parameterized methods. (Noting that a change to either behavior will be source incompatible.)

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

              Created:
              Updated: