Hi,
I've been skimming through the JCache API and wondered if the varargs arguments on EntryProcessor were really needed?
public interface Cache<K, V> {
public interface EntryProcessor<K, V, T> {
T process(Cache.MutableEntry<K, V> entry, Object... arguments);
}
<T> T invokeEntryProcessor(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments);
}
I think having those untyped parameters is a false good idea.
If the processor is going to need some parameters, those could be passed at construction time rather than passing them as Object[] at processing time (and
casting each parameter inside the processor).
I'd rather see:
public class MyEntryProcessor implements EntryProcessor<Integer, String, Long> {
private final String parameter1;
private final Long parameter2;
public MyEntryProcessor(String parameter1, Long parameter2) { ... }
public Long process(Cache.MutableEntry<Integer, String> entry) { // do something with entry and parameters }
}
than:
public class MyEntryProcessor implements EntryProcessor<Integer, String, Long> {
public Long process(Cache.MutableEntry<Integer, String> entry, Object... arguments) {
String parameter1 = (String) arguments[0];
Long parameter2 = (Long) arguments[1];
// do something with entry and parameters
}
}
What do you think?
Regards,
Xavier