读书人

为啥要返回byte[]

发布时间: 2012-11-01 11:11:31 作者: rapoo

为什么要返回byte[]
公司代码里有这样一段,大致逻辑是一个processor处理一些事情,然后返回response,但恶心的就是他在处理完事情以后还对response进行了处理,为什么?!

 public byte[] send(Map contentMap, String location) {        //忽略        try {            HttpClientResponse resp = xxTemplate.execute(method,                new HttpClientCallback() {                    public Object processResponse(HttpMethod method) throws IOException {                        return method.getResponseBody();                    }                });            int statusCode = resp.getResponseCode();            if (statusCode != HttpStatus.SC_OK) {               //忽略            } else {               //忽略            }            result = (byte[]) resp.getResponseBody();        } catch (Exception e) {            //忽略            throw new RuntimeException(e);        } finally {           //忽略        }        return result;    }


从可扩展性和可读性来看这段代码,都是不够严谨的,你只需要返回response就可以了,干嘛要做画蛇添足的事情,你让调用这个代码的人情何以堪

读书人网 >编程

热点推荐