I wonder why Java compiler doesn't trust in this line of code :
List<Car> l = new ArrayList();
and expects to have a typed ArrayList :
List<Car> l = new ArrayList<Car>();
Indeed, compiler indicates an unchecked assignment with the first case.
Why doesn't compiler see that this ArrayList() has just been created and so it's impossible to find already in it some objects other than 'Car'?
This warning would make sense if the untyped ArrayList was created before but doesn't in this case ...
Indeed, since List is typed as 'Car', all futures "l.add('object')" will be allowed only if 'object' is a 'Car'. => So, according to me, no surprise could happen.
Am I wrong ?
Thanks