JLS 3 # 12.15.2.8 allows type inference in restricted contexts. I rate it as a design error. The meaning of the expression should be free of context, which would be easier for everyone.
Since the value of getList() varies depending on its environment, which contradicts the intuition of Java programmers (never before), you find it a mystery that the first 2 compilations, and the third not. And you are not alone, this question has been raised repeatedly. They can tell us RTFS, but the more you need to read the specification, the worse the specification will be.
Of course, we must be practical if the context-sensitive interpretation is really useful and necessary. However, little is confirmed. This type of withdrawal is dangerously dangerous, and most of its used 99% is erroneously designed. It is unclear what they meant by what they consider necessary to add an inference rule of this type.
If the Java generics are "reified", that is, the value of T available for calling the method at runtime, we can imagine that such type inference would be safe and useful. However, T not available at run time, so calling the getList() context is free, it is not possible to return the correct type expected by the calling site. If there is no extralinguistic application logic that protects the sound type. Then this is hardly "static typing."
Some people went further and requested the following type of output:
Object getFoo(){ .. } Bar bar = getFoo();
because "if I wrote this, I certainly know that the return type at runtime is Bar, so stop asking me, silly compiler!"
I respect this opinion, but you should choose the language of difference. In both static and dynamic typing, the programmer knows the types, but the point of static input is that we want to explicitly write the types in the source anyway - not to help the compiler, but to benefit. The "type of withdrawal" violated this exact purpose; this should be done only if he does not create any myth to anyone who reads the code of what actually exists. Unfortunately, Java type inference is very mythical.