Contents | Prev | Next | Index
A record type is a structure consisting of a fixed number of elements, called fields, with possibly different types. In a record type declaration, for each field the name and type is specified. The scope of the field identifiers extends from the point of their declaration to the end of the record type. They are also visible within within designators refering to fields of record variables. If a record type is exported, only field identifiers with export marks will be visible outside the declaring module. They are called public fields as opposed to private fields. Private fields cannot be accessed outside the declaring module.
In the following grammar specification for record types Java specific extensions are shown in red color. They include the Java modifier and Java name directives as well as the specification of a Java interface list.
record_type ::= record field_list_seq END ::= record record_base field_list_seq END record ::= modifier RECORD record_base ::= ( parent interface_list ) parent ::= qualident ::= <empty> interface_list ::= interface_list , qualident ::= <empty> field_list_seq ::= field_list_seq ; field_list ::= field_list field_list ::= modifier field_id_list : type ::= <empty> field_id_list ::= field_id_list , field_name ::= field_name field_name ::= identdef ::= identdef java_name modifier ::= java_modifier ::= <empty> |
This compiler always maps record types to Java classes.
Record types are extensible. That is, a record type can be declared as an extension of another record type. In the example
T0 = RECORD x : INTEGER END
T1 = RECORD( T0 ) y : REAL END
T1 is a (direct) extension of T0 and T0 is the (direct) base type of T1. The base type is also called a superclass in Java. An extended type T1 consists of the fields of its base type and of the fields that are declared in T1. Identifiers declared must be different from the identifiers declared in its base type(s).
In order to better support the extension of existing Java classes, this Oberon-2 compiler also allows the specification of Java interface names as part of the record base. A Java interface is a kind of abstract class which gets implemented by specifying its name in the record base. Its field identifiers must be different from the names of fields in the base type(s) and from the names of fields in other interfaces being implemented. Also, any newly declared field identifier must be different from those in the specified interface(s).
The following are examples of record types:
RECORD
day, month, year : INTEGER;
END
RECORD
name, firstname : ARRAY 32 OF CHAR;
age : INTEGER;
salary : REAL
END
Contents | Prev | Next | Index
Canterbury Oberon-2 for JVM (Last documentation update
Jun 2, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com