Parameterized Classes

    A parameterized class Stack may be declared in Green as


class Stack(T : Any)


     proc push( x : T ) ...

     proc pop() : T ...



     var v : array(T)[];

         size : integer;


in which T must be used inside Stack as a type. This class may be used as in

var s : Stack(Person);

s.push(“Mary”, 30) );

var p : Person;

p = s.pop();


The compiler creates a new class when it finds Stack(Person). Parameter T of class Stack is replaced by Person and this new class is compiled.  Had Stack been declared as

class Stack(T : Window)



then the real parameters to Stack could only be Window and its subtypes. And the class that is parameter should define all constructors Window defines. That is, if Window defines

   proc init()

   proc init( x1, y1, x2, y2 : integer)

so should a real parameter Icon to Stack:

   var si : Stack(Icon);