Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when static initialization occurs

 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider, if you will, the following code:



if teams is run multiple times, I receive the following output:

[null, null, null, null, null, null]
[Loonies, null, null, null, null, null]
[Loonies, Dingbats, null, null, null, null]
[Loonies, Dingbats, Simpletons, null, null, null]
[Loonies, Dingbats, Simpletons, Wonkers, null, null]
[Loonies, Dingbats, Simpletons, Wonkers, Plonkers, null]
[Loonies, Dingbats, Simpletons, Wonkers, Plonkers, Melee]

why does it take it sudurn' long to get it right?
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you provide the whole program that runs the code that you gave above? I think the list should add the teams in order as specified once the method returns... I'm not quite sure why your teams() method behaves like this...

Providing more code snippets might help us to find out the details, I guess...
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me guess. This is the missing part:



;-)
I can reassure you, everything is working perfectly. It's
your core which is a bit unfortunate. The static variables
are initialized as soon as classloader loads the class. The
rest is explained in your signature.

P.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Petr Blahos:
I can reassure you, everything is working perfectly. It's
your core which is a bit unfortunate. The static variables
are initialized as soon as classloader loads the class. The
rest is explained in your signature.


I got it as well...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic