2 ms·
There is type inference for local variables indeed with var in java for a few versions now (from the top of my head it is available since 14?)
by kaba0 4y ago
There is type inference for local variables indeed with var in java for a few versions now (from the top of my head it is available since 14?)
- mypalmike 4y agoYes. And you could use Lombok to do the same before that. (Though I'm one of the weirdos who likes Java in it's explicitness, which is related directly to its verbosity. I like reading code where I can see what the local variable types are.)
- kaba0 4y ago(I believe it depends on the exact scenario. In cases where the return type is not obvious I also much prefer explicit types (eg. ConcrType a = someObj.someMethod() ), but I don’t find A a = new A() any more readable than the var version)
- mypalmike 4y agoAgreed. I'm not sure that the shortcut existing in the language is worth the fact that other devs on my team will use it in the former case.