Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37459
| From | j4n bur53 <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Are Outer Classes Loaded Lazily? |
| Date | 2017-09-24 17:39 +0200 |
| Organization | albasani.net |
| Message-ID | <oq8jji$vf6$1@news.albasani.net> (permalink) |
| References | <opu86b$k29$1@news.albasani.net> <oq13am$9v4$1@gwaiyur.mb-net.net> <5e2274e3-9af7-46e7-b4a3-dd656e639be2@googlegroups.com> |
And how about a nested class, can it have static
members? The doc says yes (the link gives itself
an example):
static class NestedButNotInner{
static int z = 5; // OK: not an inner class
}
My original question is not for inner classes but
for nested classes. I am currently working on a nested
module system, and I want to compare it with Java.
And closest to nested modules are nested classes,
i.e. locale classes which are not annonymous and
which are static. Please don't get distracted in
that I wrote:
Jan Burse wrote 20.09.2017 19:23:
> Class x=Class.forName('../Outer$Inner');
I also wrote:
> P.S.: The inner class is without synthetics,
> no access to the outer class.
Please excuse my sloppy wording, and the use
of class name "Inner". I am only intereste in
static nested classes, whether they require
loading their parent when they are loaded
itself. Basically Eric Sosman
already answered:
> java -verbose:class esosman.misc.Foo
>
> This told me that forName() caused Inner to be loaded
> but not Outer, and that getEnclosingClass() caused
> Outer to be loaded but not initialized.
But we don't see the code he was using,
maybe he can upload his test case on Gist?
Me myself, I am still lagging behind,
still struggling with instrumenting my
application, couldn't yet reproduce
what Eric Sosman wrote on some platform,
not even compiled some test so far...
lewbloch@gmail.com schrieb:
> Marcel Mueller wrote:
>> AFAIK there are no dependencies in static construction of class types,
>> regardless whether they are inner, outer or whatever.
>
> There is no such thing as "static construction" of an inner class, is there?
>
>> The only guarantee is, that a class initialization is run before any
>> member access. No more, no less. So unless you create such a dependency
>> you cannot assume the outer class to be initialized.
>>
>> Of course, the rule "before" is also fulfilled if the outer class would
>> be initialized immediately. So at the end it is implementation defined.
>> But I assume that it is unlikely that an implementation initializes the
>> outer class earlier than required, just because this could break a
>> dependency of Outer on Inner. I.e. if the initialization of the outer
>> class accesses static members of Inner.
>
> Inner classes cannot have static members except for constants.
> http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.1.3
>
> Because an inner class is associated with an instance of its outer class unless declared in a static context, and that instance cannot be created without initializing the outer class, it follows that in order for an inner class to be initialized the outer class must be initialized first.
>
> Likewise a static context won't exist unless its owning class is (being) initialized, so again an inner class cannot be initialized without the enclosing class being initialized, AIUI.
>
> The order of loading and initialization is not "at the end ... implementation defined" but at the beginning specified by the JLS.
> http://docs.oracle.com/javase/specs/jls/se8/html/jls-12.html
>
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Are Outer Classes Loaded Lazily? j4n bur53 <janburse@fastmail.fm> - 2017-09-20 19:23 +0200
Re: Are Outer Classes Loaded Lazily? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-09-20 17:45 -0400
Re: Are Outer Classes Loaded Lazily? j4n bur53 <janburse@fastmail.fm> - 2017-09-21 01:18 +0200
Re: Are Outer Classes Loaded Lazily? lewbloch@gmail.com - 2017-09-20 17:28 -0700
Re: Are Outer Classes Loaded Lazily? j4n bur53 <janburse@fastmail.fm> - 2017-09-21 09:29 +0200
Re: Are Outer Classes Loaded Lazily? j4n bur53 <janburse@fastmail.fm> - 2017-09-21 09:40 +0200
Re: Are Outer Classes Loaded Lazily? lewbloch@gmail.com - 2017-09-21 11:44 -0700
Re: Are Outer Classes Loaded Lazily? Marcel Mueller <news.5.maazl@spamgourmet.org> - 2017-09-21 21:18 +0200
Re: Are Outer Classes Loaded Lazily? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-09-21 16:20 -0400
Re: Are Outer Classes Loaded Lazily? j4n bur53 <janburse@fastmail.fm> - 2017-09-22 11:12 +0200
Re: Are Outer Classes Loaded Lazily? Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2017-09-22 15:55 -0400
Re: Are Outer Classes Loaded Lazily? j4n bur53 <janburse@fastmail.fm> - 2017-09-23 18:33 +0200
Re: Are Outer Classes Loaded Lazily? lewbloch@gmail.com - 2017-09-22 13:48 -0700
Re: Are Outer Classes Loaded Lazily? Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2017-09-22 23:46 -0400
Re: Are Outer Classes Loaded Lazily? lewbloch@gmail.com - 2017-09-25 13:23 -0700
Re: Are Outer Classes Loaded Lazily? j4n bur53 <janburse@fastmail.fm> - 2017-09-24 17:39 +0200
Re: Are Outer Classes Loaded Lazily? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-09-25 07:38 -0400
Re: Are Outer Classes Loaded Lazily? lewbloch@gmail.com - 2017-09-25 13:25 -0700
csiph-web