0
我使用generic object pooling
重用Cipher
对象。不兼容的类型:com.rh.host.Validator <T>无法转换为com.rh.host.Pool.Validator <T>
Eracom
Pool< Cipher> pool = PoolFactory.newBoundedBlockingPool(10, new CipherPicker("DESede/CBC/NoPadding"), new CipherPickerValidator());
PoolFactory
public static <T> Pool<T> newBoundedBlockingPool(int size, ObjectFactory<T> factory, Validator<T> validator) {
return new BoundedBlockingPool<T>(size, factory, validator);
}
游泳池
public interface Pool<T>
{
T get();
void shutdown();
public boolean isValid(T t);
public void invalidate(T t);
}
}
验证
public interface Validator<T>
{
public boolean isValid(T t);
public void invalidate(T t);
}
CipherPickerValidator
public final class CipherPickerValidator implements Validator <Cipher>
{
@Override
public boolean isValid(Cipher t) {
return true;
}
@Override
public void invalidate(Cipher t) {
// return false;
}
}
我得到错误PoolFactory
。它在validator
下显示一条红线。
错误
incompatible types: com.rh.host.Validator<T> cannot be converted to com.rh.host.Pool.Validator<T> where T is a type-variable:
T extends Object declared in method <T>newBoundedBlockingPool(int,ObjectFactory<T>,com.rh.host.Validator<T>)
我跟着A Generic and Concurrent Object Pool