• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

methods can run before class initialization?

 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Near the bottom of this page discussing assertions, it states that "few programmers are aware of the fact that a class's constructors and methods can run prior to its initialization." I guess I was not one of the programmers who is aware of that :roll:

Could anyone explain under what conditions this might occur?

Thanks
Geoffrey
[ March 30, 2005: Message edited by: Geoffrey Falk ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, running this class prints "0", showing that the constructor and the method "eek()" did, indeed, run before class initialization was complete (x gets set to 37 during that process.)

 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Ernest,

I tried your code and I found that you are correct, it prints 0. However, the statement on the web page about assertions does not seem to be correct.



When assertion status is disabled, this code prints "false". But the web page states that it would display true if the method ran before initialization.

Geoffrey
[ March 30, 2005: Message edited by: Geoffrey Falk ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic