4 ms·
Still no hash literal :-(
by adamlett 12y ago
Still no hash literal :-(
- exabrial 12y agoNot really a place for it in a strongly typed language like Java :/ I could maybe see language support for creating Maps or something, but in Java you're supposed to create your own Objects and let the compiler check your code for errors.
- pswenson 12y agoI assume you meant statically typed, rather than strongly typed. Swift has this: var airports: [String: String] = ["TYO": "Tokyo", "DUB": "Dublin"]
- exabrial 12y ago:D Thanks for the correction I like the swift example... Map<String, String> map = new HashMap<>(){"TYO": "Tokyo", "DUB": "Dublin"};
- dragonwriter 12y agoA hash literal syntax in a strong, statically typed language works just fine; conceptually, they aren't much different in that regard than array literals, which Java already has.
- pjmlp 12y agoThere is a JEP for alleviating the problem. http://openjdk.java.net/jeps/8048330 http://openjdk.java.net/jeps/8048330
- mhaymo 12y agoAnd that JEP basically already exists in Guava https://code.google.com/p/guava-libraries/wiki/ImmutableCollectionsExplained https://code.google.com/p/guava-libraries/wiki/ImmutableColl... `ImmutableList.of("a", "b", "c")` is not as concise as e.g. Python, but it's not bad.
- spullara 12y agoOnce you statically import the method, it is even more concise.