Home Segments Index Top Previous Next

438: Sidetrip

The instance answered by the collect: method usually belongs to the same class as the receiver, but there are exceptions. In the following, for example, the receiver is an instance of the Interval class, but the answer is an instance of the Array class, as demonstrated by the class method, which identifies the class to which an instance belongs.

Transcript show: (1 to: 5) class printString; cr. 
Transcript show: ((1 to: 5) collect: [:x | x * x]) class printString 
Transcript 
Interval 
Array