Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13467
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: trigger static init |
| References | <5605o7di8le7conanmf0g70p1ltipeqct4@4ax.com> |
| Message-ID | <KL%gr.17499$ie6.16951@newsfe14.iad> (permalink) |
| Date | 2012-04-10 12:22 -0700 |
On 4/8/12 11:28 PM, Roedy Green wrote: > What is the canonical way to explicitly trigger a static class to load > and run thestatic init without actually invoking a real method? > > you can't necessarily use newInstance since the class may not have > constructors. > > Do you have to invent some dummy static method? If you have to worry about this problem, then you've got the wrong design. Classes always have a constructor, but they may not have a Default constructor, or the constructor may be private. In any case, if you know about the class specifically before hand, then you probably have the wrong design, and should convert it to a non-static class. Probably you want dependency injection if you need only one. Perhaps as a singleton if you *really* need that, but only as a last resort.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
trigger static init Roedy Green <see_website@mindprod.com.invalid> - 2012-04-08 23:28 -0700
Re: trigger static init Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2012-04-09 10:32 +0300
Re: trigger static init Roedy Green <see_website@mindprod.com.invalid> - 2012-04-09 06:09 -0700
Re: trigger static init markspace <-@.> - 2012-04-09 09:19 -0700
Re: trigger static init Lew <lewbloch@gmail.com> - 2012-04-09 10:33 -0700
Re: trigger static init Lew <lewbloch@gmail.com> - 2012-04-09 10:36 -0700
Re: trigger static init Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-04-11 12:52 +0000
Re: trigger static init Patricia Shanahan <pats@acm.org> - 2012-04-11 07:04 -0700
Re: trigger static init Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-04-11 15:30 +0000
Re: trigger static init Patricia Shanahan <pats@acm.org> - 2012-04-11 09:32 -0700
Re: trigger static init Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-04-22 16:09 +0000
Re: trigger static init Steven Simpson <ss@domain.invalid> - 2012-04-12 07:38 +0100
Re: trigger static init Patricia Shanahan <pats@acm.org> - 2012-04-12 00:36 -0700
Re: trigger static init Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-04-11 09:39 -0500
Re: trigger static init Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-04-11 14:56 +0000
Re: trigger static init Lew <noone@lewscanon.com> - 2012-04-11 08:08 -0700
Re: trigger static init glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-04-09 09:18 +0000
Re: trigger static init Roedy Green <see_website@mindprod.com.invalid> - 2012-04-09 04:57 -0700
Re: trigger static init Lew <lewbloch@gmail.com> - 2012-04-09 10:31 -0700
Re: trigger static init Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-04-10 12:22 -0700
csiph-web