I'm trying to figure out why the compiler throws
test(capture<? extends Serializable>) in Predicate cannot be applied to (Serializable)
for test(e.getValue().getData())
and how I could solve the issue.
The code throwing the compiler error is the following
private Map<Predicate<? extends Serializable>, TaggedData<? extends Serializable>> scheduledData = new HashMap<>();
public synchronized <T extends Serializable> void conditionalSend(String tag, T data, Predicate<T> condition) {
scheduledData.put(condition, new TaggedData<T>(tag, data));
scheduledData.entrySet()
.stream()
.filter(e -> e.getKey().test(e.getValue().getData()))
.forEach(e -> send(e.getValue()));
}
My TaggedData class is defined like this
class TaggedData<T extends Serializable> implements Serializable {
private static final long serialVersionUID = 1469827769491692358L;
private final String tag;
private final T data;
TaggedData(String tag, T data) {
this.tag = tag;
this.data = data;
}
String getTag() {
return tag;
}
T getData() {
return data;
}
}