From Liberty Eiffel Wiki
Jump to navigation Jump to search

A definition of Void

The Void notation corresponds to an expression having no particular type. It is used to indicate the lack of an object. Void is an elementary predefined and unmodifiable notation. Void can be used like this:

if my_variable = Void then
   io.put_string("There's no object :-(")
   io.put_string("There's an object !")

Of course, to call a method, there must be an object. Thus, it is more frequent to see the opposite test in many programs:

if my_variable /= Void then

Graphically, the lack of an object in a variable or an attribute simply corresponds to:

Graphical representation of Void

Void can also be used on the right side of the assignment sign to voluntarily lose the reference to an object:

my_variable := Void

Of course, after the execution of the previous line, my_variable does not reference any object anymore.

In case of a variable which is an expanded type, the use of Void has no meaning because such a variable always contains an object. Actually, remember that in the case of an expanded variable, the object is directly stored in the variable without an intermediary pointer. It is impossible not to have an object when using an expanded variable. For example, the comparison between a variable of type INTEGER and Void has no meaning because the variable necessarily points out an INTEGER and thus can never correspond to the lack of object. For this reason, it is forbidden to compare Void with a variable of an expanded type.

For the same reasons, the use of Void on the right side of the assignment sign when the left side is of an expanded type is not allowed.

Current is never Void!

From the principle of object-oriented programming itself, Current always points to an object. Comparing Current with Void has no meaning and such a comparison is also forbidden.