Skip to content

Instantly share code, notes, and snippets.

@rch850
Created January 29, 2013 13:20
Show Gist options
  • Save rch850/4664164 to your computer and use it in GitHub Desktop.
Save rch850/4664164 to your computer and use it in GitHub Desktop.
Java 8 の lambda で遊んでる
public class HttpSample {
public static void main(String[] args) {
sendRequest("http://example.com/", data -> {
System.out.println("data is " + data);
}, error -> {
System.out.println("error ><");
});
sendRequest("http://naiyo.naiyo/", data -> {
System.out.println("data is " + data);
}, error -> {
System.out.println("error ><");
});
}
static void sendRequest(String url, HttpListener onSuccess, HttpListener onError) {
if (url.indexOf("naiyo") != -1) {
onError.call("naiyo");
} else {
onSuccess.call("Receive from " + url);
}
}
static interface HttpListener {
public void call(String data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment