3 ms·
Can some explain the fist example says infers the type is right there in black and white var foo = new ArrayList<String>(); It literally says exactly what fo
by walshemj 9y ago
Can some explain the fist example says infers the type is right there in black and white
var foo = new ArrayList<String>();
It literally says exactly what foo is !!
- kinghajj 9y agoYes, but in current Java one would have to write ArrayList<String> foo = new ArrayList<String>() Or, at least List<String> foo = new ArrayList<String>() Whereas with `var`, as you show, the compiler infers the type. Proponents of this point out exactly what you did: the type is right there, so why should the programmer have to write it twice?
- stickfigure 9y agoBecause nobody actually writes this twice. n,<return>,A,r,L,<return>,S,t,r,<return>,Cmd-Option-V,<return> The IDE autocompletes everything, extract-to-variable does most of the heavy lifting.
- ionised 9y ago> List<String> foo = new ArrayList<String>() List<String> foo = new ArrayList<>() > so why should the programmer have to write it twice? You wouldn't.