Java Developers: var Is Your Friend

Stian Soiland-Reyes2018/08/15

Todd Ginsberg argues why var in Java 10 is not a anything-goes like in VBasic, but a nice short-hand for local variables where the type is unambiguously defined anyway, e.g.

    private List<String> names;
    for(var name: names) {
        System.out.println("Name: " + name);

would continue to work even when names is changed from String to Person. The duplicated type info of name is here almost irrelevant and thus can be used with var -- obviously this is more useful for more complicated types like MyThingFactory<Something,Going,On> than String.