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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CLASSES Field Modifiers 8.3.1<br />

of accessing the origin class variable access the same object, evidenced by the<br />

fact that the value of the reference equality expression (§15.21.3):<br />

q.origin==Point.origin<br />

is true. Further evidence is that the incrementation:<br />

p.origin.useCount++;<br />

causes the value of q.origin.useCount to be 1; this is so because p.origin and<br />

q.origin refer to the same variable.<br />

8.3.1.2 final Fields<br />

A field can be declared final (§4.12.4). Both class and instance variables<br />

(static and non-static fields) may be declared final.<br />

It is a compile-time error if a blank final (§4.12.4) class variable is not definitely<br />

assigned (§16.8) by a static initializer (§8.7) of the class in which it is<br />

declared.<br />

A blank final instance variable must be definitely assigned (§16.9) at the end<br />

of every constructor (§8.8) of the class in which it is declared; otherwise a compile-time<br />

error occurs.<br />

8.3.1.3 transient Fields<br />

Variables may be marked transient to indicate that they are not part of the persistent<br />

state of an object.<br />

If an instance of the class Point:<br />

class Point {<br />

int x, y;<br />

transient float rho, theta;<br />

}<br />

were saved to persistent storage by a system service, then only the fields x and y<br />

would be saved. This specification does not specify details of such services; see<br />

the specification of java.io.Serializable for an example of such a service.<br />

8.3.1.4 volatile Fields<br />

DRAFT<br />

As described in §17, the <strong>Java</strong> programming language allows threads to access<br />

shared variables. As a rule, to ensure that shared variables are consistently and<br />

reliably updated, a thread should ensure that it has exclusive use of such variables<br />

by obtaining a lock that, conventionally, enforces mutual exclusion for those<br />

shared variables.<br />

<strong>The</strong> <strong>Java</strong> programming language provides a second mechanism, volatile<br />

fields, that is more convenient than locking for some purposes.<br />

199

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

Saved successfully!

Ooh no, something went wrong!