Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37439

Re: Are Outer Classes Loaded Lazily?

From j4n bur53 <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: Are Outer Classes Loaded Lazily?
Date 2017-09-21 01:18 +0200
Organization albasani.net
Message-ID <opusvk$5se$1@news.albasani.net> (permalink)
References <opu86b$k29$1@news.albasani.net> <opunhc$c73$1@dont-email.me>

Show all headers | View raw


for nested classes the method getEnclosingClass(),
calls getDeclaringClass(), which is native. but I
guess it will use the outer_class_info_index in
the class file format.

which is a little unnecessary, since it could derive
the outer class name from the inner class name,
lastIndexOf('$') or somesuch.

but your testing somehow indicates that getDeclaringClass()
indeed works lazily. Can this be? This would imply
that it can be possible that the static of Inner

might be called before the static of Outer?

Or is this an artefact of reflection. Since in
real code we habe a name Outer.Inner and since
this mentions Outer, it would load Outer?

Eric Sosman schrieb:
> On 9/20/2017 1:23 PM, j4n bur53 wrote:
>> Assume I have a nested inner class Inner,
>> and I do the following:
>>
>>     Class x=Class.forName('../Outer$Inner');
>
>     One or two tiny little problems here ... ;)
>
>> And then I do the following:
>>
>>     Class y=x.getEnclosingClass();
>>
>> Is the enclosing class '../Outer' already
>> loaded during the Class.forName() or only
>> when I do getEnclosingClass() ?
>
>     You'd need to scrutinize the JLS and/or the JVMS to be
> certain.  That can be difficult: They seek exactness and
> sometimes find it on the other side of opacity ...
>
>     Instead, I ran a quick experiment: I wrote suitable
> Outer and Inner classes, plus a Foo class to make the
> forName() and getEnclosingClass() calls sandwiched by
> some System.out.println() calls, and ran it as
>
>     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.  (I also found
> that Inner was initialized during forName() if it was
> made `static', but couldn't tell what happened when it
> was non-`static'.)
>

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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