Skip to main content
added 578 characters in body
Source Link

This seems to be more of a (software-)philosophic question here.

ArrayList as a utility class is designed to be helpful in a wide context of possible use-cases.

Contrary to your hidden claim that accepting null as a valid value should be discouraged, there are many examples where the null value is perfectly legal.

The single most important reason is that null is the do not know equivalent of any reference type, including framework types. SoThis implies that null cannot be replaced in any case by a more fluent version of the nothing value.

So, lets say you store the Integers 1, 3, 7 in your arraylist at its corresponding index: Due to some computation, you want to get the element at index 5, so what your array should return is: "no value stored". This could be achieved through returning null or a NullObject. In most cases returning the built in null value is expressive enough. After calling a method that can return null and using its return value a check of the returned value against null is quite common in modern code.

This seems to be more of a (software-)philosophic question here.

ArrayList as a utility class is designed to be helpful in a wide context of possible use-cases.

Contrary to your hidden claim that accepting null as a valid value should be discouraged, there are many examples where the null value is perfectly legal.

The single most important reason is that null is the do not know equivalent of any reference type, including framework types. So null cannot be replaced in any case by a more fluent version of the nothing value.

This seems to be more of a (software-)philosophic question here.

ArrayList as a utility class is designed to be helpful in a wide context of possible use-cases.

Contrary to your hidden claim that accepting null as a valid value should be discouraged, there are many examples where the null value is perfectly legal.

The single most important reason is that null is the do not know equivalent of any reference type, including framework types. This implies that null cannot be replaced in any case by a more fluent version of the nothing value.

So, lets say you store the Integers 1, 3, 7 in your arraylist at its corresponding index: Due to some computation, you want to get the element at index 5, so what your array should return is: "no value stored". This could be achieved through returning null or a NullObject. In most cases returning the built in null value is expressive enough. After calling a method that can return null and using its return value a check of the returned value against null is quite common in modern code.

Source Link

This seems to be more of a (software-)philosophic question here.

ArrayList as a utility class is designed to be helpful in a wide context of possible use-cases.

Contrary to your hidden claim that accepting null as a valid value should be discouraged, there are many examples where the null value is perfectly legal.

The single most important reason is that null is the do not know equivalent of any reference type, including framework types. So null cannot be replaced in any case by a more fluent version of the nothing value.