Java 在映射中投射值

Java 在映射中投射值,java,google-app-engine,casting,Java,Google App Engine,Casting,我正在使用memcache(Google App Engine)并使用getAll()在批处理中检索多个缓存项。我的缓存项是: private Map<String, Set<Long>> cacheEntries; // key: String, value: Set<Long> 这显然是失败的,因为返回了对象,并且需要设置。所以我试着像这样投射地图: cacheEntries = (Map<String, Set<Long>>)

我正在使用memcache(Google App Engine)并使用getAll()在批处理中检索多个缓存项。我的缓存项是:

private Map<String, Set<Long>> cacheEntries; // key: String, value: Set<Long>
这显然是失败的,因为返回了对象,并且需要设置。所以我试着像这样投射地图:

cacheEntries = (Map<String, Set<Long>>) cache.getAll(keys);
cacheEntries=(Map)cache.getAll(key);
但是编译器告诉我

Incompatible types, cannot cast Map<String, Object> to Map<String, Set<Long>

不兼容类型,无法将映射强制转换为映射您可以在强制转换为
映射之前将其强制转换为原始
映射

cacheEntries=(Map)(Map)cache.getAll(key);
如果不需要原始类型警告,也可以使用
Map

cacheEntries = (Map<String, Set<Long>>) cache.getAll(keys);
Incompatible types, cannot cast Map<String, Object> to Map<String, Set<Long>
cacheEntries = (Map<String, Set<Long>>)(Map)cache.getAll(keys);