next up previous
Next: Methods Up: Java Grammar Extensions Previous: Instantiation


A class definition can be parameterized by using the following syntax:

<ClassDeclaration> -> [<ClassModifiers>] class <idn>
    ["[" <params> "]"] [<where>] [<Super>]
    [<Interfaces>] <ClassBody>

As was the case for interfaces, the params of the class can be used as types within the class. Also, code in the ClassBody can call the routines introduced in the where clause. Such a call is legal provided the routine being called is introduced in the where clause and has a signature that matches the use. The syntax of the call depends on what kind of routine is being called: for an ordinary method, the syntax x.m() is used to call the method; for a constructor, the syntax new T() is used; and for a static method the syntax T.m() is used.

Andrew C. Myers, Joseph A. Bank, Barbara Liskov
Copyright © 1996 Association for Computing Machinery