Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2858
| Newsgroups | comp.lang.java.help |
|---|---|
| Date | 2013-11-18 14:51 -0800 |
| References | <8ed39e6c-ccea-480e-b3a3-8b802957ede8@googlegroups.com> |
| Message-ID | <ca817691-9fe0-41d4-8da0-8cb8fc7e1bf5@googlegroups.com> (permalink) |
| Subject | Re: how to access static instance variables defined in static initializer block |
| From | Marc B <marc.at.compass@gmail.com> |
Ok,. I found an answer..
I have to _declare_ te static variables outside te static initializer block and _initialize_ them in the static initializer
static int sint2 = 8;
static {
sint2 = 8;
System.out.println("Initializing static variable sint2: " + sint2);
}
Then I can refer to Holder.sint2.
//
Still don't see why adding static int sint2 = 8; to contructor or main() doesn't work:
public Holder(){
static int sint2 = 9;
}
Marc
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to access static instance variables defined in static initializer block Marc B <marc.at.compass@gmail.com> - 2013-11-18 14:42 -0800
Re: how to access static instance variables defined in static initializer block Marc B <marc.at.compass@gmail.com> - 2013-11-18 14:51 -0800
Re: how to access static instance variables defined in static initializer block Marc B <marc.at.compass@gmail.com> - 2013-11-18 15:01 -0800
Re: how to access static instance variables defined in static initializer block markspace <markspace@nospam.nospam> - 2013-11-18 15:26 -0800
Re: how to access static instance variables defined in static initializer block Lew <lewbloch@gmail.com> - 2013-11-27 16:05 -0800
Re: how to access static instance variables defined in static initializer block Roedy Green <see_website@mindprod.com.invalid> - 2013-11-30 12:41 -0800
Re: how to access static instance variables defined in static initializer block Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-12-01 00:23 +0200
csiph-web