You probably don't want to do that because you lose the static typing that
generics are meant to provide. A more appropriate implementation would be
something like:

public class ExampleCache implements Cache<String, Object> {
    @Override
    public Object get( String key ) throws CacheException {
        return mc.get( key );
    }

    // Other methods
}


If your cache contains only one type of object that is more specific than
Object, you could potentially use that type instead and perform a (unsafe)
cast within the definition of get(String).


On Wed, Jul 20, 2011 at 1:22 AM, James Whetstone -
[email protected] wrote:

> **
>  This question might be more about proper Java than it is about the
> Cache<K,V> interface, but I wouldn't know where else to ask this.
>
> I'm implementing a Cache<K,V> interface for memached and I'm using
> spymemcached.  The spymemcached client only takes a string as the key.
>
> So I've implemented, for example, the get(K key) method it by casting the
> arguments as shown below.
>
> @Override
>
> *public*
> V get(K key) *throws* CacheException {
>
> *return* *(V) *mc.get((String) key);
>
> }
>
> So the question is, is this safe/proper use of Java in this context?  It
> doesn't look right to me.
>
> Thanks,
> James
>
>
>

Reply via email to