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

static block reading values from other class static block

 
sanju dharma
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have one static class , say , Database.java and other class DbConnection.java. I have static block in both classes. Can I use static variable values from one class into static block of another class. I mean what happens if second class gets loaded ( JVM ) earlier than second class. Will first class's value be null ? For example
public class DbConnection {
static {
if(Database.bInsert)
// do something
}
what will happen if DbConnection gets loaded first than Database. Will bInsert value null/default?
Thanks,
Sudhir
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give it a try. Let's say A references B in a static block. The first time you reference A its static block is evaluated, and it references B so B's static block is evaluated before you can "get" anything from it. Ought to work fine. If for some reason you reference B first, it will be initialized before A, and that's just fine.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic