If I am writing
List<String> list1 = new ArrayList<String>();
list1.add(null);
list1.add(null);
Java allows that . Why ?? Any use of list1[0] will any way result into NPE .
Java allows that. Why?
Because the List
is a collection of object references. Since null
is a valid reference (for all types), then the compiler allows statements like list1.add(null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With