NoFieldlessObjects
DRAFT

Misconception:

If a class has no instance variables, and one allocates an object of that class, the result is null, because there is no data to point to. Moreover, in instance methods of such classes, this does not refer to anything (because there are no fields to refer to).

Incorrect

Objects without instance variables can't exist

Correct

Correction
Here is what's right.

Wrong. Even if an object has no fields, it still is an object and it still is allocated on the heap. It may be very small (because it has no fields), but it still exists and it still uses some memory (e.g., at least it has some meta information that determines what class the object has).

The identity of an object can be useful, even if the object contains no state otherwise.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.