Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Created April 1, 2018 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yohhoy/07e4d059c0f54c63f3cb4872e6474971 to your computer and use it in GitHub Desktop.
Save yohhoy/07e4d059c0f54c63f3cb4872e6474971 to your computer and use it in GitHub Desktop.
var x = new ArrayList<>();
>>
15.9. Class Instance Creation Expressions
A class instance creation expression is a poly expression (§15.2) if it uses the diamond form for type arguments to the class, and it appears in an assignment context or an invocation context (§5.2, §5.3). Otherwise, it is a standalone expression.
We say that a class is instantiated when an instance of the class is created by a class instance creation expression. Class instantiation involves determining the class to be instantiated (§15.9.1), the enclosing instances (if any) of the newly created instance (§15.9.2), and the constructor to be invoked to create the new instance (§15.9.3).
<<
>>
15.9.1. Determining the Class being Instantiated
(snip)
If a class instance creation expression does not declare an anonymous class, then:
* If the class instance creation expression is unqualified, then:
(snip)
The class being instantiated is specified by the Identifier in ClassOrInterfaceTypeToInstantiate. If TypeArguments is present, then the class has type arguments given by TypeArguments; if <> is present, then the class will have its type arguments inferred in §15.9.3; otherwise, the class has no type arguments.
<<
>>
15.9.3. Choosing the Constructor and its Arguments
Let C be the class being instantiated. To create an instance of C, i, a constructor of C is chosen at compile time by the following rules.
First, the actual arguments to the constructor invocation are determined:
* (snip)
* Otherwise, the arguments to the constructor are the arguments in the argument list of the class instance creation expression, if any, in the order they appear in the expression.
Second, a constructor of C and corresponding throws clause and return type are determined:
* (snip)
* If the class instance creation expression uses <>, then:
* If C is not an anonymous class, let D be the same as C. (snip)
* If D is a class, let c1...cn be the constructors of class D. (snip)
* A list of methods m1...mn is defined for the purpose of overload resolution and type argument inference. For all j (1 ≤ j ≤ n), mj is defined in terms of cj as follows:
* (snip)
(snip)
If the class instance creation expression is a poly expression, then its compatibility with a target type is as determined by §18.5.2.1, using mj as the selected method m.
<<
>>
18.5.2.1. Poly Method Invocation Compatibility
If the method invocation expression is a poly expression (§15.12), its compatibility with a target type T is determined as follows.
(snip)
Otherwise:
* Let B2 be the bound set produced by reduction in order to demonstrate that m is applicable in §18.5.1.
<<
>>
18.5.1. Invocation Applicability Inference
Given a method invocation that provides no explicit type arguments, the process to determine whether a potentially applicable generic method m is applicable is as follows:
* Where P1, ..., Pp (p ≥ 1) are the type parameters of m, let α1, ..., αp be inference variables, and let θ be the substitution [P1:=α1, ..., Pp:=αp].
* An initial bound set, B0, is generated from the declared bounds of P1, ..., Pp, as described in §18.1.3.
* (snip)
* C is reduced (§18.2) and the resulting bounds are incorporated with B1 to produce a new bound set, B2.
* Finally, the method m is applicable if B2 does not contain the bound false and resolution of all the inference variables in B2 succeeds (§18.4).
<<
>>
18.1.3. Bounds
When inference begins, a bound set is typically generated from a list of type parameter declarations P1, ..., Pp and associated inference variables α1, ..., αp. Such a bound set is generated as follows. For each l (1 ≤ l ≤ p):
* If Pl has no TypeBound, the bound αl <: Object appears in the set.
* (snip)
<<
>>
18.2. Reduction
Reduction is the process by which a set of constraint formulas (§18.1.2) is simplified to produce a bound set (§18.1.3).
(snip)
<<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment