This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final reference variables K&B SCJP 6

 
Harry Henriques
Ranch Hand
Posts: 206
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Please examine the code snippet below. I don't understand why K&B say that "reference variables must be initialized before the constructor completes." The code below compiles and runs just fine.

Thanks,

K&B Two Minute Drill Chapter 1 wrote:final variables have the following properties:
final variables cannot be reinitialized once assigned a value.
final reference variables cannot refer to a different object once the object has been assigned to the final variable.
final reference variables must be initialized before the constructor completes.


C:\temp>cat Final.java



C:\temp>vi Final.java

C:\temp>gvim.exe Final.java

C:\temp>javac Final.java

C:\temp>java Final
thisReference says hello
10
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33696
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That comment means final instance (or static) variables must be initialized before the constructor completes.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic