JAVA T 范型使用例子

   public  T getResultData(Result result,Class clazz) {
   T ret = null ;
   if (result != null) {
      if (!ResultEnum.SUCCESS.code.equals(result.getRetCode())) {
         log.error(result.getRetMsg());
         throw new LogicException(result.getRetMsg());
      } else if (null != result.getData()) {
         //return (T) result.getData();
      }
   }
   try{
      ret = clazz.newInstance();
   }catch (Exception e){
      log.error("getResultData类转换异常!");
      throw new LogicException("getResultData类转换异常!");
   }
   return ret;
}

你可能感兴趣的:(Java日常技术总结)