3 ms·
For your example, sure. But it's not uncommon (in my opinion) to write stuff like EnumMap<FooEnum, BarClass> map = new EnumMap<FooEnum, BarClass>(FooEnum.
by unwind 11y ago
For your example, sure.
But it's not uncommon (in my opinion) to write stuff like
EnumMap<FooEnum, BarClass> map = new EnumMap<FooEnum, BarClass>(FooEnum.class);
which to me ought to read something like
var map = new EnumMap<FooEnum, BarClass>();
Of course, I don't do a lot of Java programming these days and perhaps my first example is simply broken due to ignorance.
When I wrote something very similiar to that last week, I failed to figure out how to avoid repeating the type signature, and was annoyed.
- michaelt 11y agoIt's not quite as short as you'd like, but since Java 7 came out in 2011, it's been possible to write: EnumMap<FooEnum, BarClass> map = new EnumMap<>(FooEnum.class); using the "diamond operator" [1]. In fact, my IDE even provides automatic hints to make use of it! With that said, I do think java has too much pro-long-method-and-variable-name culture. [1] http://www.javaworld.com/article/2074080/core-java/jdk-7--the-diamond-operator.html http://www.javaworld.com/article/2074080/core-java/jdk-7--th...
- glogla 11y agoYou can already do something similar, instead you write Map<SomeComplexTypes> map = new HashMap<>();
- deleted 11y ago[deleted]