I have to check null condition for too many methods. how can i do it in generic way rather than repeating the same steps or Is it possible to write?
Here's my code:
<Student>
<Name></Name>
<RollNumber></RollNumber>
</Student>
I should throw an exception If user gives null value for Name or RollNumber field. I have already written code below. which is working correctly but i need to write generic method for both scenario and it should work the same as below,
if(student.getName() == null) {
System.out.println("Name is required to create Student Data");
}
if(student.getRollNumber() == null) {
System.out.println("RollNumber is required to create Student Data");
}
Note : Name is String and RollNumber is an Integer
Can you please give me an IDEA?
This question may already have an answer here: Avoiding “!= null” statements in Java? 44 answers
My Question is "I don't want avoiding null statement. If user gives null value How Can we throw an exception in generic way?"