我通过 pojo 的 getter 方法获取对象中的金额,但是金额 getter 方法的返回类型在 pojo 中设置为字符串,如下所示
//setting need to be done in pojo
private String amount;
public String getAmount() {
return amount;
}
让我们在下面说有对象 h 我正在检索它
h.getAmount()
现在我需要开发一个验证器来验证该金额应该是整数类型,如果不是,那么它将抛出异常请告知我如何开发一个单独的方法来检查金额是否为整数和在此基础上会返回 true 或 false ,如下图
// Validate the amount is in integer
private boolean isValidAmount (String Amount) {
boolean valid = false;
//code to check whether the Amount is integer or not, if integer then
//return true else return false
}
我已经更新了帖子,因为它引发了数字格式异常,请告知