2023年12月2日发(作者:)

java调用接口显示参数类型错误_关于java泛型设计接口导致的参数类型不匹配问题...1.设计了一个接口用于包装其它 pojo,以计算是否过期public interface CatchWrapper{public long getCatchedTime();public T getValue();public boolean valid();}某一个实现:public class DeviceCatchWrapper implements CatchWrapper {private final long catchedTime;private final Device device;private static final long CATCH_TIME = 20*1000;public DeviceCatchWrapper(Device device) { = device;catchedTime = tTimeMillis();}@Overridepublic long getCatchedTime() {return catchedTime;}@Overridepublic Device getValue() {return device;}@Overridepublic boolean valid() {return tTimeMillis() - catchedTime < CATCH_TIME;}}另有一个管理类,主要是删除过期的缓存public class DeviceCatchWrapperManager {private static final ScheduledExecutorService service = gleThreadScheduledExecutor();private final ConcurrentMap> catchStore;private final long initialDelay;private final long delay;private TimeUnit unit;private volatile boolean stop = false;public DeviceCatchWrapperManager(ConcurrentMap> catchStore, long initialDelay,long delay, TimeUnit unit) {tore = catchStore;lDelay = initialDelay; = delay; = unit;}/*** 周期性检查过期的缓存,然后删除*/public void startLoop() {leWithFixedDelay(new Runnable() {@Overridepublic void run() {for (Entry> entry : et()) {if (stop)break;String key = ();CatchWrapper cw = ue();if (!()){n("Device catch manager --------------->remove:"+key);(key, cw);}}}}, initialDelay, delay, unit);}/*** 停在对缓存进行过期检查*/public void stop() {stop = true;wnNow();}}但是真正构造函数 传参数报错private final ConcurrentMap catchMap = new ConcurrentHashMap<>();下面的报错,参数不对private final DeviceCatchWrapperManager catchManager = new DeviceCatchWrapperManager(catchMap, 2, 2,);改怎么解决这个错误 或者 该怎么设计接口或者改进呢?