JDK-8061650 : 15.12.2.5: Most specific for generic class constructors different than treatment of methods
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 7,8
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-10-21
  • Updated: 2015-12-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_majorUnresolved
Related Reports
Relates :  
Description
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.)
Comments
One implication: anonymous classes are defined to have constructors that invoke 'super(...)' -- the meaning of this expression is not directly defined, instead treating it like generated source that in turn can mostly be interpreted using the standard rules (15.9.5.1). But if diamond is supported in combination with anonymous classes (see JDK-8073593), then the meaning of this is well-defined: new C<>("hi") {} // refers to C(String) while the meaning of the generated source is not: class Anon extends C<String> { public Anon(String arg) { super(arg); } // ambiguous } We can work around this in the spec, but it's an awkward inconsistency.
23-02-2015