Re:All New Java Language Features Since Java 21
by matt2000 on Saturday September 06, 2025 @12:01PM
(#45150433)
I would argue that it helps me when performing maintenance to see and correct where types may have changed. Not always, and sometimes it is busy work I agree, but overall I prefer it.
Re:All New Java Language Features Since Java 21
by cokely on Saturday September 06, 2025 @02:15PM
(#45151589)
Yeah I generally avoid using 'var' to elide method return types for that reason. In my early phase of var enthusiasm I even had it result in a bug that would have been caught if the type had been made explicit.
I do still really like it in the `var list = new ArrayList<String>()` case though.
Re:All New Java Language Features Since Java 21
by watwut on Saturday September 06, 2025 @01:53PM
(#45151409)
Modify it when? If the interface renames? IDE does that. If the actual return type changes? They you do have to check that place whether it is still valid.
Maintenance involves a lot of reading of unknown code. That is literally the situation where you are rewiting var to specific types to figure out what is going on.
That isn't necessarily a huge win: it does force a compile change that isn't obvious from the source. And a refactoring tool could have performed the code change automatically so it's not as big a deal as it might have been.