by Traubenfuchs · 8y ago · 0 comments
var lowercaseIds = ids.stream().map(String::toLowerCase);
and an additional .collect(Collectors.toList())
if you don't want a Stream instance. (var is Java 10, though I believe it should not be used in production code, ever)Is that your opinion of var in general, or something about Java's implementation of it? If the former, I'm really curious why, as a C# dev who's used it for many years.
Sometimes I explore source code on GitHub, excessive use of var makes reading it very uncomfortable.
Turning it around, what are the benefits of var? Slightly increased typing speed. More time is spent reading source code than writing it and var makes reading harder and writing easier, so it's not worth the trade in my opinion.
RE your sibling comment about dynamic: I primarily use it with json. It's useful for things like one-off error responses where you just need to grab a message or code to return/throw and there's really no benefit from introducing a class for that one usage. I did once work on a project where that was attempting to re-use some awful legacy code in a new app, and they leaned on dynamic a lot to make the legacy code work without to re-architect it correctly. It was about as terrible as you're imagining.
But I am a c# dev, and in the early days when var was introduced a lot of people avoided var because of misunderstanding of how it works. People thought it was dynamic rather than inferred, is it the same here?
See my reason for not using it above.
As someone who holds no mastery over C#: Is it appropriate to ever use dynamic anywhere besides horrifying interop code?