Created
November 24, 2015 06:31
-
-
Save ecstasy2/f117da27eb74d0875c6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface CmdFunction{ | |
public void call(Object param); | |
} | |
// This is the function where you need a function passed in as a param | |
public void tellMeWhatTodo(CmdFunction cmd) { | |
if (something) { | |
cmd.call('me'); | |
} | |
} | |
// Somewhere else | |
class MyClass { | |
var bar(){ | |
} | |
void foo(){ | |
// Now I am want to pass bar() to tellMeWhatTodo | |
tellMeWhatTodo(new CmdFunction(){ | |
public void call(param) { | |
// Run some code | |
bar(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment