Java构造函数

来源:互联网 发布:艾媒数据统计 编辑:程序博客网 时间:2024/06/03 20:29
public class Util_HttpPost {String url = "";HttpPost httpRequest;List<NameValuePair> params;String result;//服务器返回结果public Util_HttpPost(String url, Map<String, String> map) {// 请求数据// httpRequest = new HttpPost(Variable.accessaddress+"dbutil"); httpRequest = new HttpPost(url);// 创建参数 params = new ArrayList<NameValuePair>();//遍历传进来的map参数Set set = map.keySet();Iterator it = set.iterator();while (it.hasNext()) {String key = (String) it.next();String value = map.get(key);params.add(new BasicNameValuePair(key, value));}/*不要在构造函数里调用执行方法,因为构造函数只能返回类对象实例通过这样来调用commodityId = new Util_HttpPost(Variable.accessaddress+ "sendcommodity", getParamsMap()).post(); post();  */}public String post() {