Java. , . , , , -. , , , , IndexOutOfBounds ClassCastException .
public interface DelegatedFunction<T> {
T call(Object... args);
}
public class DoesSomeDelegatedTask {
private List<DelegatedFunction<String>> delegatedFunctions = new ArrayList<>(1);
public void addFunction(DelegatedFunction<String> function) {
delegatedFunctions.add(function);
}
public void execute() {
for (DelegatedFunction<String> function: delegatedFunctions) {
System.out.println(function(something, someotherthing, whatever));
}
}
}
public class Main {
public static void main(String[] args) throws Exception {
DoesSomeDelegateTask doer = new DoesSomeDelegatedTask();
doer.addFunction(new DelegatedFunction<String> () {
@Override
public String call(Object... args) {
return ((SomeThings) args[0]).whatever((SomeOtherThing) args[1]
}
}
doer.execute();
}
}