Skip to content

Instantly share code, notes, and snippets.

@jsfan3
Created May 8, 2019 12:59
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 jsfan3/3a66e711fd0fd233c5e4c467184adb7a to your computer and use it in GitHub Desktop.
Save jsfan3/3a66e711fd0fd233c5e4c467184adb7a to your computer and use it in GitHub Desktop.
Java Runnable With Arg
public interface RunnableWithArg<T> {
/**
* Similar to the runnable interface but it accepts an argument
*
* @param arg any type of argument
*/
public void run(T arg);
}
@jsfan3
Copy link
Author

jsfan3 commented May 8, 2019

Example of usage

Suppose to have a method like the following that needs a RunnableWithArg as callback:

CameraUtilities.takePhotoFromCamera(getTakeAvatarCallback());

in this case, the implementation of getTakeAvatarCallback() can start with:

    /**
     * Callback for taking a new avatar photo from Camera or Gallery
     * @return 
     */
    private RunnableWithArg<Image> getTakeAvatarCallback() {
       return new RunnableWithArg<Image>() {
           @Override
           public void run(Image image) {
               // write your code here
           }
       };
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment