I was reading the java 8 language specification type inference. It says that
List<String> ls = new ArrayList<>()
would be first reduced
ArrayList<α> -> List<String>
and then to
α <= String
and at the end to
α = String
I'm having a hard time understanding how the reduction of the constraint
ArrayList<α> -> List<String> to α <= String
was derived. It would be a great help if anyone can point out the logic using the java 8 language spec.
Here's the link to the reduction
Thanks #Holger for the explanation. Following is my take on the derivation of
new ArrayList<> -> List<String> to ArrayList<α> -> List<String>
Please correct me if I'm wrong.
First to find the temporary method for the constructor we use #15.9.3
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.
If the class instance creation expression uses <> to elide class type arguments, a list of methods m1...mn is defined for the purpose of overload resolution and type argument inference.
Then #18.5.2 is used to derive
ArrayList<α> -> List<String>
Because of being a poly expression and not having any wild card type parameters;
- Otherwise, the constraint formula ‹R θ → T› is reduced and incorporated with B2.