next up previous contents
Next: Methods Up: Attributes Previous: Attributes   Contents

Void

All variables in Cool are initialized to contain values of the appropriate type. The special value void is a member of all types and is used as the default initialization for variables where no initialization is supplied by the user. (void is used where one would use NULL in C or null in Java; Cool does not have anything equivalent to C's or Java's void type.) Note that there is no name for void in Cool; the only way to create a void value is to declare a variable of some class other than Int, String, or Bool and allow the default initialization to occur, or to store the result of a while loop.

There is a special form isvoid expr that tests whether a value is void (see Section 7.11). In addition, void values may be tested for equality. A void value may be passed as an argument, assigned to a variable, or otherwise used in any context where any value is legitimate, except that a dispatch to or case on void generates a runtime error.

Variables of the basic classes Int, Bool, and String are initialized specially; see Section 8.


next up previous contents
Next: Methods Up: Attributes Previous: Attributes   Contents