java8"s Optional doesn"t make the program concise, so don"t talk about him. Okay, thank you
.after looking at the following question, I think this design is very good
can null.method () in Java be designed to return null?
now the version of java is that every time a method of null is called, an exception of NullPointerException is thrown.
I don"t think java should be designed this way.
because this design will lead to a huge increase in the amount of code, if I want to ensure that there is no null pointer problem in the program, I need to make a non-null judgment before every method call!
otherwise, no matter how well your program is written, you can"t avoid the problem of null pointers!
I dare to say this because people who have heard Ali say before, "No matter how well your program is written, you can"t avoid the problem of null pointers!" And in addition to our own experience in development over the past few years, you can also think about it: for so many years, we have developed seriously, thought carefully, and tried to think comprehensively, but who has not encountered NullPointerException,? this shows that people can"t cover everything. We all develop according to normal logic, and no one can write a line of code and think 100% possible.
in development, the database is suddenly emptied, who can guarantee that their program will not report a null pointer?
in this case, our program is abnormal and cannot be executed downwards, which is not acceptable to me. I think if there is a problem that the database is emptied, you just tell me in the result returned to me, this is listed as null, why do you want my whole program to execute abnormally?
in many cases, we can accept that some fields in the database are sometimes null, and sometimes have values.
if sometimes you cannot accept that the result is null, but get the result of Null, it is obvious that there is a problem in the program, so you should go to debug to find the problem.
I think it"s the programmer"s job, not the java language"s job.
java now throws exceptions to all calls to null methods, which is tantamount to calling bug, for programmers, but creates a lot of code that could have been avoided