Skip to main content
more realistic code snippet
Source Link
x-code
  • 1.1k
  • 8
  • 11

The statement

File f = null;

is valid and useful (I don't think I need to explain why). It is likewise useful to have a collection of files, some of which may be null.

List<File> files = new ArrayList<File>();
// use my collection of files
// .add...
// not using this one anymore:
files.set(3, null);

The usefulness of collections that may contain null objects proceeds directly from the usefulness of objects that may be null. It is really as simple as that.

The statement

File f = null;

is valid and useful (I don't think I need to explain why). It is likewise useful to have a collection of files, some of which may be null.

List<File> files = new ArrayList<File>();
files.add(null);

The usefulness of collections that may contain null objects proceeds directly from the usefulness of objects that may be null. It is really as simple as that.

The statement

File f = null;

is valid and useful (I don't think I need to explain why). It is likewise useful to have a collection of files, some of which may be null.

List<File> files = new ArrayList<File>();
// use my collection of files
// ....
// not using this one anymore:
files.set(3, null);

The usefulness of collections that may contain null objects proceeds directly from the usefulness of objects that may be null. It is really as simple as that.

added 76 characters in body
Source Link
x-code
  • 1.1k
  • 8
  • 11

IfThe statement

File f = null;

is valid and useful (it is), thenI don't think I need to explain why). It is it not likewise useful to have a collection of files, some of which may be null?.

List<File> files = new ArrayList<File>();
files.add(null);

Null objects andThe usefulness of collections that may contain null objects are both usefulproceeds directly from the usefulness of objects that may be null. It is really as simple as that.

If

File f = null;

is valid and useful (it is), then why is it not likewise useful to have a collection of files, some of which may be null?

List<File> files = new ArrayList<File>();
files.add(null);

Null objects and collections that may contain null objects are both useful. It is really as simple as that.

The statement

File f = null;

is valid and useful (I don't think I need to explain why). It is likewise useful to have a collection of files, some of which may be null.

List<File> files = new ArrayList<File>();
files.add(null);

The usefulness of collections that may contain null objects proceeds directly from the usefulness of objects that may be null. It is really as simple as that.

Source Link
x-code
  • 1.1k
  • 8
  • 11

If

File f = null;

is valid and useful (it is), then why is it not likewise useful to have a collection of files, some of which may be null?

List<File> files = new ArrayList<File>();
files.add(null);

Null objects and collections that may contain null objects are both useful. It is really as simple as that.