Comment

Comment by vivin

This is pretty nice. Hope it goes through. It's about time that we had local-variable inference in Java. It does mean that the diamond can't be used this way:

  var list = new ArrayList<>();
There is no way to infer the type of the generic parameter. So we will go back to doing:

  var list = new ArrayList<String>();
Which isn't a big deal IMO because the generic parameters had to be specified on the LHS anyway to use the diamond. You also end up using fewer characters in general with var even without being able to use the diamond.

Regarding val vs let, I prefer let simply because it's harder to accidentally type let vs typing var instead of val (or vice versa).

parent vivin 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton