Lunar Programming Language

by David A. Moon
January 2017 - January 2018



Generic Classes

A generic class represents a potentially infinite set of subclasses of itself that are generated by supplying generic actual parameters for the class's generic formal parameters.

Each particular subclass of a generic class is only generated once, when it is first referenced.

Because a generic class is a bundle, it also represents a potentially infinite set of constructor functions generated in the same way. Invoking a generated constructor makes an instance of the generated subclass with the same generic actual parameters.

Distinct generated subclasses of a generic class never stand in a subtype relationship regardless of any subtype relationship among their generic actual parameters. (There is neither covariance nor contravariance.)

Syntax

A generic class uses the same defining syntax as a regular class, except that the class name is followed by a generic formal parameter list enclosed in [ ] brackets.

For examples of generic classes, see Sequences


Previous page   Table of Contents   Next page



Creative Commons License
Lunar by David A. Moon is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Please inform me if you find this useful, or use any of the ideas embedded in it.
Comments and criticisms to dave underscore moon atsign alum dot mit dot edu.