官术网_书友最值得收藏!

3.11 Record

When a number of data items are chunked together into a unit, the result is a data structure. Data structures can have very complex structure, but in many applications, the appropriate data structure consists simply of a sequence of data items. Data structures of this simple variety can be either arrays or records.

The term “record” is not used in Java. A record is essentially the same as a Java object that has instance variables only, but no instance methods. Some other languages, which do not support objects in general, nevertheless do support records. The C programming language, for example, is not object-oriented, but it has records, which in C go by the name “struct.” The data items in a record —in Java, an object’s instance variables—are called the fields of the record. Each item is referred to using a field name. In Java, field names are just the names of the instance variables. The distinguishing characteristics of a record are that the data items in the record are referred to by name and that different fields in a record are allowed to be of different types. For example, if the class Person is defined as:

record在Java中沒有被使用。本質上講,一個記錄與Java中的對象實例是一樣的,但是它沒有實例的方法。在Java中,字段名正好就是實例變量的名字。區分一個記錄中的字段是通過記錄中的數據項名字來實現的,并且記錄中不同的字段允許有不同的類型。

class Person {
       String name;
       int id_number;
       Date birthday;
       int age;
    }

then an object of class Person could be considered to be a record with four fields. The field names are name, id_number, birthday, and age. Note that the fields are of various types: String, int, and Date.

Because records are just a special type of object, I will not discuss them further.

主站蜘蛛池模板: 凉山| 寻甸| 扎赉特旗| 平舆县| 岗巴县| 扶风县| 锦屏县| 清远市| 长岭县| 石景山区| 德庆县| 汤阴县| 新绛县| 措勤县| 广昌县| 蓝田县| 金堂县| 葫芦岛市| 清水河县| 嵩明县| 营口市| 眉山市| 娱乐| 长葛市| 威海市| 那坡县| 遵义市| 镇安县| 阿拉善左旗| 衡东县| 册亨县| 陇西县| 庄浪县| 错那县| 吉首市| 普定县| 怀化市| 崇仁县| 饶阳县| 紫阳县| 内黄县|