我在Core java中遇到了问题。 考虑具有称为age的属性的Employee类。预防未使用客户端验证的年龄为负数
class Employee{
private int age;
public void setAge(int age);
}
我的问题是如何限制/防止setAge(INT年龄)方法,使得其只接受正数,它不应该允许负数,
Note: This has to be done without using client side validation.how do i achieve it using Java/server side Validation only.The validation for age attribute should be handled such that no exception is thrown
毫无疑问,你不想抛出异常,你必须说出你想要发生的事情,那就是你应该实现的。当一位服务员接受你的订单时,你是否开始了你不想要的饭菜? – 2011-02-04 15:21:45
@彼得我明白。这在采访中被问到了ysday.hence im发布了同样的问题,而intwer告诉我有一个laternate解决方案,以及他没有透露 – Deepak 2011-02-04 15:22:44