Chapter 4
Types, Values, and Variables
The organization of this chapter parallels the chapter on Types, Values, and Variables in the Java Language Specification (second edition), which begins as follows:
The Java programming language is a strongly typed language, which means that every variable and every expression has a type that is known at compile time. Types limit the values that a variable (§4.5, JLS) can hold or that an expression can produce, limit the operations supported on those values, and determine the meaning of the operations. Strong typing helps detect errors at compile time.
The types of the Java programming language are divided into two categories: primitive types and reference types. The primitive types (§4.2, JLS) are the
booleantype and the numeric types. The numeric types are the integral typesbyte,short,int,long, andchar, and the floating-point typesfloatanddouble. The reference types (§4.3, JLS) are class types, interface types, and array types. There is also a special null type. An object (§4.3.1, JLS) is a dynamically created instance of a class type or a dynamically created array. The values of a reference type are references to objects. All objects, including arrays, support the methods of classObject(§4.3.2, JLS). String literals are represented byStringobjects (§4.3.3, JLS).
Names of types are used (§4.4, JLS) in declarations, casts, class instance creation expressions, array creation expressions, class literals, and
instanceofoperator expressions.
A variable (§4.5, JLS) is a storage location. A variable of a primitive type always holds a value of that exact type. A variable of a class type T can hold a null reference or a reference to an instance of class T or of any class that is a subclass of T. A variable of an interface type can hold a null reference or a reference to any instance of any class that implements the interface. If T is a primitive type, then a variable of type "array of T" can hold a null reference or a reference to any array of type "array of T"; if T is a reference type, then a variable of type "array of T" can hold a null reference or a reference to any array of type "array of S" such that type S is assignable (§5.2, JLS) to type T. A variable of type
Objectcan hold a null reference or a reference to any object, whether class instance or array.
4.1 The Kinds of Types and Values
(Cf. JLS. §4.1.)
TO DO
4.2 Primitive Types and Values
(Cf. JLS. §4.2.)
TO DO
4.2.1 Integral Types and Values
(Cf. JLS. §4.2.1.)
TO DO
4.2.2 Integer Operations
(Cf. JLS. §4.2.2.)
TO DO
4.2.3 Floating-Point Types, Formats, and Values
(Cf. JLS. §4.2.3.)
TO DO
4.2.4 Floating-Point Operations
(Cf. JLS. §4.2.4.)
TO DO
4.2.5 The <code>boolean Type and <code>boolean</code> Values</h3>
(Cf. JLS. §4.2.5.)
TO DO
4.3 Reference Types and Values
(Cf. JLS. §4.3.)
TO DO
4.3.1 Objects
(Cf. JLS. §4.3.1.)
TO DO
4.3.2 The Class Object
(Cf. JLS. §4.3.2.)
TO DO
4.3.3 The Class String
(Cf. JLS. §4.3.3.)
TO DO
4.3.4 When Reference Types Are the Same
(Cf. JLS. §4.3.4.)
TO DO
4.4 Where Types Are Used
(Cf. JLS. §4.4.)
TO DO
4.5 Variables
(Cf. JLS. §4.5.)
TO DO
4.5.1 Variables of Primitive Type
(Cf. JLS. §4.5.1.)
TO DO
4.5.2 Variables of Reference Type
(Cf. JLS. §4.5.2.)
TO DO
4.5.3 Kinds of Variables
(Cf. JLS. §4.5.3.)
TO DO
4.5.4 final Variables
(Cf. JLS. §4.5.4.)
TO DO
4.5.5 Initial Values of Variables
(Cf. JLS. §4.5.5.)
TO DO
4.5.6 Types, Classes, and Interfaces
(Cf. JLS. §4.5.6.)
TO DO
Specification Table of Contents.
The organization of this chapter parallels the chapter on Types, Values, and Variables in the Java Language Specification (second edition).
The original of this specification is at http://docs.codehaus.org/display/GroovyJSR.
