What one of the following is best practice to handle Null Pointer exception?
i) int noOfStudents = line.listStudents().count;
ii) int noOfStudents = getCountOfStudents(line);
public int getCountOfStudents(List line){if(line != null) {if(line.listOfStudents() != null) { return line.listOfStudents().size();}}throw new NullPointerException("List is empty");}
Correct Answer Option (ii)
বিসিএস, ব্যাংক, প্রাইমারি সহ সরকারি বেসরকারি চাকুরীর পরীক্ষার প্রস্তুতির জন্য ডাউনলোড করুন Bissoy অ্যাপ