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

when does a variable is initialized ?

 
ashwin bhawsar
Ranch Hand
Posts: 62
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for a local variable :
i know that we need to initialize a local variable before using it

for static variable:

What does this error says ? variable 'j' should be initialized automatically as it is a static one, then why we get this error.
Why dont we get the same error for local variables. Why for local variable its says that it must be initialized before using instead of saying that we cannot use it before it is not defined ? At what stage a variable gets defined ? is it after completing the statement ?
 
Wim Vanni
Ranch Hand
Posts: 96
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java operators

Read the above article and pay particular attention to the right to left evaluation. It should make things clearer.

Cheers,
Wim
 
ashwin bhawsar
Ranch Hand
Posts: 62
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, cool so what this article says is that
All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.

This gives the answer for the question, so in both the cases
The compiler tries to evaluate the RHS of the '=' where it need i and j , and throws an error because it cannot find it.

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