4 ms·
Yes, but in current Java one would have to write ArrayList<String> foo = new ArrayList<String>() Or, at least List<String> foo = new ArrayList<String>() Whe
by kinghajj 9y ago
Yes, 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.