Ian,

This is not true: this statement casts the result of the invocation of
get() to HashMap<String, UserDetails>. A cast of _cache to
HashMap<String, UserDetails> with subsequent invocation to get() would
look as follows:

((HashMap<String, UserDetails>) _cache).get(user.getInstance());

Also, the exception says: "java.lang.ClassCastException:
java.util.ArrayList cannot be cast to java.util.HashMap", which
indicates an attempt to cast an ArrayList to a HashMap.

Furthermore, the expression "new HashMap(_cache)" - as simple and easy
as it may look - creates a copy of the whole content of the cache. As
I don't know the exact implementation of the cache's Map operation, I
would never issue such a statement. It can be assumed that this
involves getting all objects in the cache, which may be an expensive
operation. The constructor of HashMap internally iterates over all
entries of the cache (see its source code).

Generics are basically thrown away at compile time, i.e they don't
influence the behavior at runtime (see also message of the
ClassCastException).

However, a source of the error may be that the put() has
user.getInstanceID() as key, while the get has user.getInstance().
Depending on what you put with the key user.getInstance(), this could
not be casted to a HashMap<String, UserDetails> (or simply HashMap at
runtime).

On Mar 1, 8:06 pm, Ian Marshall <ianmarshall...@gmail.com> wrote:
> I refer to the GAE/J-specific post in the GAE group of the same name
> of link:
>
>  http://groups.google.com/group/google-appengine/browse_thread/thread/...
>
> Your line
>
>   HashMap<String, UserDetails> userMap = (HashMap<String,
> UserDetails>)_cache.get(user.getInstance());
>
> involves casting a javax.cache to a java.util.HashMap. Both of these
> classes implement the java.util.Map interface, but it looks like one
> may not be cast directly to the other as you attempt.
>
> I have never used javax.cache, but have you tried using the HashMap
> constructor HashMap(Map m) to get:
>
>   HashMap<String, UserDetails> mapTemp = new HashMap(_cache);
>   HashMap<String, UserDetails> userMap =
> mapTemp.get(user.getInstance());
>
> This might make it easier to identify exactly where the exception is
> occurring.
>
> Enjoy?

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to