10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.1 <strong>The</strong> Kinds of Types and Values TYPES, VALUES, AND VARIABLES<br />

34<br />

1. At run-time, classes and interfaces are loaded by the <strong>Java</strong> virtual machine<br />

using class loaders. Each class loader defines its own set of classes and interfaces.<br />

As a result, it is possible for two loaders to load an identical class or<br />

interface definition but produce distinct classes or interfaces at run-time.<br />

2. Type arguments and type variables (§4.4) are not reified at run-time. As a<br />

result, different parameterized types (§4.5) are implemented by the same class<br />

or interface at run time. Indeed, all invocations of a given generic type declaration<br />

(§8.1.2, §9.1.2 )share a single run-time implementation.<br />

A consequence of (1) is that code that compiled correctly may fail at link time<br />

if the class loaders that load it are inconsistent. See the paper Dynamic Class<br />

Loading in the <strong>Java</strong> Virtual Machine, by Sheng Liang and Gilad Bracha, in Proceedings<br />

of OOPSLA ’98, published as ACM SIGPLAN Notices, Volume 33,<br />

Number 10, October 1998, pages 36-44, and <strong>The</strong> <strong>Java</strong> Virtual Machine <strong>Specification</strong>,<br />

Second <strong>Edition</strong> for more details.<br />

A consequence of (2) is the possibility of heap pollution (§4.12.2.1). Under<br />

certain conditions, it is possible that a variable of a parameterized type refers to an<br />

object that is not of that parameterized type. <strong>The</strong> variable will always refer to an<br />

object that is an instance of a class that implements the parameterized type. See<br />

(§4.12.2) for further discussion.<br />

4.1 <strong>The</strong> Kinds of Types and Values<br />

<strong>The</strong>re are two kinds of types in the <strong>Java</strong> programming language: primitive types<br />

(§4.2) and reference types (§4.3). <strong>The</strong>re are, correspondingly, two kinds of data<br />

values that can be stored in variables, passed as arguments, returned by methods,<br />

and operated on: primitive values (§4.2) and reference values (§4.3).<br />

Type:<br />

PrimitiveType<br />

ReferenceType<br />

<strong>The</strong>re is also a special null type, the type of the expression null, which has no<br />

name. Because the null type has no name, it is impossible to declare a variable of<br />

the null type or to cast to the null type. <strong>The</strong> null reference is the only possible<br />

value of an expression of null type. <strong>The</strong> null reference can always be cast to any<br />

reference type. In practice, the programmer can ignore the null type and just pretend<br />

that null is merely a special literal that can be of any reference type.<br />

DRAFT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!