This doesn't seem to work (compiler complains that Something
's getFoo()
method doesn't implement HasFoo
) and I can't figure out why or how to fix it....
enum FooKey { BLOB1, DONUT, ... }
interface HasFoo
{
public Object getFoo(FooKey k);
}
class Something implements HasFoo
{
private Map<FooKey, Object> map;
@SuppressWarnings("unchecked")
@Override
<T> T getFoo(FooKey k)
{
return (T)map.get(k);
}
/* other stuff deleted */
}
I want both an interface and I also want to be able to do stuff like
Something something = ...
Blob blob1 = something.getFoo(FooKey.BLOB1);
Donut donut = something.getFoo(FooKey.DONUT);