Note that in the current implementation, the entrySet will return a copy of the internal storage:
public Set entrySet() {
// First, clear all entries that have been in cache longer than the
// maximum defined age.
deleteExpiredEntries();
// TODO Make this work right synchronized (this) {
return new HashSet(map.entrySet());
}
}
This internal storage stores not the raw types, but wrapped raw types. Unwrapping should occur before the EntrySet is returned:
public Set<Entry<K, V>> entrySet() {
// First, clear all entries that have been in cache longer than the
// maximum defined age.
deleteExpiredEntries();
// TODO Make this work right synchronized (this) {
final Map<K,V> result = new HashMap<K,V>();
for (final Entry<K, DefaultCache.CacheObject<V>> entry : map.entrySet()) {
result.put(entry.getKey(), entry.getValue().object);
}
return result.entrySet();
}
}
Note that this still does not return an EntrySet that backs the collection, but at least the correct objects are now returned.