-sharp discussion-sharp Why is java designed to have the concept of NullPointerException (null pointer)?

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


java dialect


if you do not report an exception, you (programmer) may not be able to find problems in your program, because people are lazy, and if you do not report an exception, it is estimated that few people will judge or catch a null pointer, which is likely to lead to a result: there is already a big problem in your program, but you can't feel it.

but from the user's point of view, they can feel a lot of these problems: nothing is shown where the price is supposed to be displayed, nothing happens when it is supposed to proceed to the next step, and there are no false reports, and so on.


according to the discussion upstairs:
your attitude is only your personal attitude, and the enterprise needs to be as stable as a dog. If it is a large enterprise like Ali, a null pointer can track how many servers.
so doing java,java according to your ideas can not become an enterprise development language. Basically, you can only entertain yourself

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4260b-449c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4260b-449c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?