Parametric polymorphism: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Updated C3)
m (→‎{{header|Wren}}: Changed to Wren S/H)
Line 1,577:
 
Fortunately, we can simulate PP by passing an extra parameter to a collection class's contructor to specify the type of values to be used for that particular instantiation. We can then use this to guard against the wrong type of values being passed to the class's other methods.
<syntaxhighlight lang="ecmascriptwren">class BinaryTree {
construct new(T, value) {
if (!(T is Class)) Fiber.abort ("T must be a class.")
9,488

edits