Skip to content

Instantly share code, notes, and snippets.

@dhaeb
Created September 9, 2015 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaeb/c22832d6d9c530f0e264 to your computer and use it in GitHub Desktop.
Save dhaeb/c22832d6d9c530f0e264 to your computer and use it in GitHub Desktop.
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