Why does Map
fail to compile, but Map
This is not a failure in Guava, but rather in the way Java resolves generics, and it's something we can't control. =(
Believe us: this is something that we spent a lot of time on. In this issue, Kevin mentions that we attempted no less than fifteen approaches for trying to get it so that you didn't have to explicitly specify these type parameters.
If you're only interested in the case of ImmutableMap.builder().build()
, that is, with no entries in the map...then you should be using ImmutableMap.of()
. That won't have any funny issues with generics: it'll just work.