関数へのポインターとして変数を渡すにはどうすればよいですか? リファクタリングしたい次のコードがあります
public static HttpResponse getJSONEntityFromURL(Context context, String url) throws ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
httpget.addHeader("Accept", "application/json");
httpget.addHeader("Content-Type", "application/json; charset=UTF-8");
HttpResponse response;
response = httpclient.execute(httpget);
return response;
}
このようなものに
public static HttpResponse getJSONEntityFromURL(Context context, String url) throws ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
setHeaders(httpget);
HttpResponse response;
response = httpclient.execute(httpget);
return response;
}
private static void setHeaders(HttpRequestBase httpget) {
httpget.addHeader("Accept", "application/json");
httpget.addHeader("Content-Type", "application/json; charset=UTF-8");
}
httpget パラメータをポインタとして渡す必要があると思いますか?