Why does implicit type inference only work in a job?

I know that by using generic in an assignment, a method can implicitly know the type of the return type by looking at the type of the left variable.

Example from the Google collection:

List<String> l = Lists.newArrayList()

My question is why it does not work for a method or higher type of output?

Example:

List<List<String>> ll = Lists.newArrayList();
ll.put(Lists.newArrayList()); // doesn't work

Is this specified in JLS? If so, why? If not, is this some kind of improvement I can expect from Java 7?

This annoyed me because it seems like we have a problem in Java, as if I have a problem in Delphi a long time ago when I cannot make a call call with a chain like:

C c = a.b().c();

In Delphi (IIRC) you need to do:

B b = a.b();
C c = b.c();

Looks like 'dejavu'

+2
source share
1 answer

, : , , .

, /: , , .

. Java - # 3, ( , ).

EDIT: , JLS - 15.12.2.8:

(§5.2) S, R - [...]

" ", .

+3

All Articles