I have an interface that defines a method that does some computation
public interface Computable {
public Result compute(Foo foo);
}
I want to also pass in a set of arguments to the computation that can be peeled off. I can hack this up, but I am wondering if there's an elegant solution with generics
and var args
. Something like...
public class Parameter<K,V> {
private final K key;
private final V value;
public Parameter(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return this.key;
}
public V getValue() {
return value;
}
}
But then I'm lost as to how going through each parameter from the list of parameters I would be able to simply get the key value pairs with their types inferred. Can someone help me? Has this not already been built into the JDK?
EDIT with example:
In a concrete implementation we'd have....
public Result compute(Foo foo,
Parameter ...parameters) {
// Here I'd like to get each parameter, and have it know it's key type and value type
for(Parameter p : parameters) {
p.getKey();
p.getValue()
//implementers know what to do with their parameters
}
}