很难为情地问这个问题很可能很简单,但似乎找不到答案.
我有一个可缓存的接口
/**
K denotes the type of the key of a cacheable object
*/
public interface Cacheable<K extends Serializable> extends Serializable{
K getKey();
}
然后我有一个缓存来存储可缓存的内容
/**
Cache that can store an object of type T and it's key which is of type K
*/
public interface Cache<K, T extends Cacheable>{
Optional<T> get(K key);
T put(T cacheable);
}
虽然这会起作用,但我希望这更好,因为上面没有表示t和K之间的关系.换句话说,t.getKey应该返回K的事实在这里并不强制.
我一直在寻找下面的东西,但显然它是不可编译的.我该怎么做?
public interface Cache<K, T<K> extends Cacheable<K>>