转载

Java根据参数返回相应类

问题初衷:如何根据参数变换方法的返回类型(参数为 类)

解决方案采用泛型解决(<T>)

解决方案:

下面方法是放在工具类(例:YslRequestUtil)

1 public <T> T  response(Object requestentity, T responseentity, String Url, String metodname){
2         //强转传递参数
3         T hfGetPolicyResponse = (T) resxstream.fromXML(result);
4         System.out.println(hfGetPolicyResponse);
5 
6         return hfGetPolicyResponse;
7     }        

调用工具类方法:

1 GetPolicyByRtPatRes getPolicyByAirLine = yslRequestUtil.response(getPolicyByAirLineReq, new GetPolicyByRtPatRes(), "http://www.baidu.com", "metodname");

原文  http://www.cnblogs.com/xiaohaojs/p/11760289.html
正文到此结束
Loading...