Timeline for Why does java.util.ArrayList allow to add null?
Current License: CC BY-SA 3.0
23 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 21, 2022 at 12:04 | comment | added | barneypitt | Null values are used universally in Java, throughout literally billions of lines of code, to mean whatever the hell the developer needed null to mean. If you think "all* nulls are bad, you need to use a different language. But java allows nulls, so they not only could but added to lists, but should be added to lists in contexts where null is valid. If you disagree, then good luck representing a List of method arguments without using null. | |
Aug 21, 2022 at 11:53 | comment | added | barneypitt | Why was it hard to spot where the bug was? It sounds like the easiest thing in the world - identify methods which modify this ArrayList; make them check for null. | |
Sep 26, 2019 at 8:57 | answer | added | Nanobody | timeline score: -1 | |
Apr 3, 2018 at 19:30 | comment | added | riwalk |
@JIXiang You're oversimplifying what null is. "Missing" is just one of several potential interpretations of null . Other valid interpretations could be "Unknown," "Not Applicable," or "Uninitialized." What null represents depends on the application. As the Python community would say, "In the face of ambiguity, refuse the temptation to guess." Refusing to hold null in a container that is perfectly capable of doing so would be just that--a guess.
|
|
Apr 12, 2016 at 4:22 | comment | added | xji |
The simple answer is just that null is the default way to represent missing data in Java, whether you like it or not. In fact a lot of people don't like it and make it an argument for functional programming-style things. The most upvoted answer makes no sense/doesn't capture the essence of the issue.
|
|
S Mar 18, 2015 at 14:56 | history | suggested | DontDivideByZero | CC BY-SA 3.0 |
Code formatting
|
Mar 18, 2015 at 13:47 | review | Suggested edits | |||
S Mar 18, 2015 at 14:56 | |||||
Jan 14, 2015 at 4:42 | history | protected | gnat | ||
Oct 9, 2014 at 0:08 | answer | added | x-code | timeline score: 4 | |
Jul 16, 2014 at 11:01 | answer | added | Mare Infinitus | timeline score: 4 | |
Jul 16, 2014 at 10:54 | comment | added | Mare Infinitus | Can you provide more information on why it should not be allowed? If it is just a matter of taste, then the less restrictive should be prefered. | |
Sep 6, 2012 at 18:22 | vote | accept | Alfredo Osorio | ||
Sep 3, 2012 at 16:11 | answer | added | James | timeline score: 8 | |
Sep 3, 2012 at 15:57 | history | edited | gnat |
edited tags
|
|
Sep 3, 2012 at 15:45 | answer | added | NiteRain | timeline score: 2 | |
Sep 3, 2012 at 15:13 | comment | added | Shivan Dragon | I believe that the answers given here cover well the question. Maybe one thing that should be mentioned is: don't take everything that's in the JDK as holly and perfect, and then whack your head trying to understand why it is so "perfect". Some things are (honest, IMHO) mistakes, that remained there due to backwards compatibility and that's that. Even the Java creators admit it, just read Joshua Bloch's books to see his critique of certain Java APIs. At any rate, your question comes down to weather there isn't a more elegant way to catch NPE in Java. The answer is, no, but there should be. | |
Sep 3, 2012 at 15:12 | history | edited | Alfredo Osorio | CC BY-SA 3.0 |
edited title
|
Sep 3, 2012 at 15:09 | comment | added | Joachim Sauer |
The Guava Project has a pretty interesting page on that topic (they don't allow null in most of their collections).
|
|
Sep 3, 2012 at 15:01 | answer | added | gnat | timeline score: 38 | |
Sep 3, 2012 at 15:01 | history | tweeted | twitter.com/#!/StackProgrammer/status/242638344738205698 | ||
Sep 3, 2012 at 14:50 | answer | added | Stephen C | timeline score: 21 | |
Sep 3, 2012 at 14:43 | answer | added | Sam Holder | timeline score: 33 | |
Sep 3, 2012 at 14:30 | history | asked | Alfredo Osorio | CC BY-SA 3.0 |