Cache.get() and the usage of generics
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
play framework |
New
|
Undecided
|
Unassigned |
Bug Description
I'm wondering what the param clazz is needed for in the following method, found in the Cache class.
/**
* Convenient clazz to get a value a class type;
* @param <T> The needed type
* @param key The element key
* @param clazz The type class
* @return The element value or null
*/
@SuppressWa
public static <T> T get(String key, Class<T> clazz) {
return (T) cacheImpl.get(key);
}
AFAIK clazz isn't doing anything here. The return type is derived from the type of the variable in the calling context, as in:
Foo foo = cache.get("key")
The first <T> would set the type of T to Foo. Then we happen to require a second param containing a Class instance of type Class<Foo>, but I don't think that is needed at all for the requested functionality (to return the cached object with the correct type and avoid casting).