Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

initializer block

 
Udit Manektala
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's this problem that confuses me about intializer blocks.

Why is this code not wrong\giving me an error. After all, it is redeclaring the variable width, right ?

I came across this in the questions of the Mughal Rasmussen book and tried it myself and it works. I just need to know Why??... it doesnt make any sense to me.

 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Udit Manektala:
There's this problem that confuses me about intializer blocks.

Why is this code not wrong\giving me an error. After all, it is redeclaring the variable width, right ?

I came across this in the questions of the Mughal Rasmussen book and tried it myself and it works. I just need to know Why??... it doesnt make any sense to me.


The instance initializer is declaring a local variable named "width". This variable is assigned the value of 15, not used afterwards, and goes out of scope when the initializer completes.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic