Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java 8 - Function abstraction can be difficult. Any Ideas to make it better?
@SuppressWarnings("unchecked") // It's a cast, I am responsible.
private void callToMethod(int i, int j) {
if(f instanceof BiFunction){
BiFunction<Integer, Integer, Boolean> callable = (BiFunction<Integer, Integer, Boolean>) f;
callable.apply(0, 1);
} else if(f instanceof BiConsumer){
BiConsumer<Integer, Integer> callable = (BiConsumer<Integer, Integer>) f;
callable.accept(i, j);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.