大多数情况下,方法重载时可以在参数少的方法中之前调用参数多的方法,如以下例子
public static JsonResult fail(ServiceException e) {
/*JsonResult jsonResult = new JsonResult();
jsonResult.setState(e.getServiceCode().getValue());
jsonResult.setMessage(e.getMessage());
return jsonResult;*/
return fail(e.getServiceCode(),e.getMessage());
}
public static JsonResult fail(ServiceCode serviceCode, String message) {
JsonResult jsonResult = new JsonResult();
jsonResult.setState(serviceCode.getValue());
jsonResult.setMessage(message);
return jsonResult;
}