(no title)
frje1400 | 5 months ago
var items = new HashMap();
Instead of
HashMap items = new HashMap();
That's the point of var. It reduces noise a lot in some situations.
frje1400 | 5 months ago
var items = new HashMap();
Instead of
HashMap items = new HashMap();
That's the point of var. It reduces noise a lot in some situations.
vbezhenar|5 months ago
There are valid use-cases for `var`, but IMO this feature should not have been added to the language, as it's too dangerous and most people won't use it responsibly.
tombert|5 months ago
For argument types you don’t have var, so methods that take in a map can stay abstract and you can still pass in the implementation-specific version into those without casting it to the interface.
ETA:
I guess I am trying to say that if you want to be abstract, they should be at the argument or properties level. Local variables should be used locally. I agree that generally speaking you should try and prefer using Map for anything shared across different parts of code but I am not convinced it’s bad to have var be implementation-specific; if your method is big enough to where swapping out implementations like this will take a lot of time, your method is probably too big anyway.
pico303|5 months ago
jsnsndn|5 months ago
You would like to use Map<Key, Value> items = new HashMap<>() since in general you do not want implementation detail leaking into contracts
vips7L|5 months ago