不兼容的类型:com.rh.host.Validator<T> 无法转换为 com.rh.host.Pool.Validator<T>
incompatible types: com.rh.host.Validator<T> cannot be converted to com.rh.host.Pool.Validator<T>
我使用 generic object pooling
重用 Cipher
对象。
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>)
文章的部分代码似乎已被修改。
错误是试图分配一个
com.rh.host.Validator
到
com.rh.host.Pool.Validator
写成这样就明白发生了什么事了。您有两个不相关的类型,都称为 Validator
。该文章似乎在其自身的文件中呈现嵌套类型。
因此请确保每个名称只有一个定义。并且可能会找到一篇更好的文章。
我使用 generic object pooling
重用 Cipher
对象。
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>)
文章的部分代码似乎已被修改。
错误是试图分配一个
com.rh.host.Validator
到
com.rh.host.Pool.Validator
写成这样就明白发生了什么事了。您有两个不相关的类型,都称为 Validator
。该文章似乎在其自身的文件中呈现嵌套类型。
因此请确保每个名称只有一个定义。并且可能会找到一篇更好的文章。