Created
January 29, 2013 13:20
-
-
Save rch850/4664164 to your computer and use it in GitHub Desktop.
Java 8 の lambda で遊んでる
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 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