Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Semantics

461

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
461
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 6. class FinalTest { public static FinalTest ft; public static int [] x = new int[1]; static void foo() { public final int a; int [] myX = FinalTest.x; public final int [] b,c,d; int j = myX[0]; public final Point p; FinalTest f1 = ft; public final int [][] e; if (f1 == null) return; // Guaranteed to see value public FinalTest(int i) { // set in constructor? int i1 = f1.a; // yes a = i; int i2 = f1.b[0]; // yes int i3 = f1.c[0]; // yes int [] tmp = new int[1]; int i4 = f1.d[0]; // yes tmp[0] = i; int i5 = myX[0]; // no b = tmp; int i6 = f1.p.x; // yes int i7 = f1.e[0][0]; // yes c = new int[1]; // use j, i1 ... i7 c[0] = i; } } FinalTest.x[0] = i; d = FinalTest.x; // Thread 1: p = new Point(); // FinalTest.ft = new FinalTest(42); p.x = i; // Thread 2; e = new int[1][1]; // FinalTest.foo(); e[0][0] = i; } Figure 3: Subtle points of the revised semantics of ﬁnal 6
• 8. static void foo() { Improper p = proper; Improper i = improper; if (p == null) return; // Possible Resultsclass Improper { public final Point p; Improper i1 = i; // reference to point or null public static Improper proper; int i2 = i.x; // 42 or 0 public static Improper improper; Improper p1 = p; // reference to point public Improper(int i) { int p2 = p.x; // 42 p = new Point(); Improper i3 = i; // reference to point or null p.x = i; int i4 = i.x; // 42 or 0 improper = this; } } } // Thread 1: // Improper.proper = new Improper(42); // Thread 2; // Improper.foo(); Figure 4: Improperly Constructed Final Fields 8