• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can you use static sections? (NOT static variables, this is diff)

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know we can't use static variables (which makes sense since that implies a class-global variable), but can we use static sections (which simply imply that when the class is loaded into the VM, this section is kicked off).

For example:



1. Is that allowed?
2. Would that be the same across all vendors (I'm thinking it would have to be - NOT the time when it's loaded, just the FACT that it's loaded and kicked off)
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know we can't use static variables

Not entirely true, read-only static fields are allowed.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert,
Yes it is allowed. Whether it is a good idea or not depends on what you do in the static section.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Robert,
Yes it is allowed. Whether it is a good idea or not depends on what you do in the static section.


Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!