Cache.get() and the usage of generics

Bug #632753 reported by Per Wiklander
6
This bug affects 1 person
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
     */
    @SuppressWarnings("unchecked")
    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).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.