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


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

Re: Are Outer Classes Loaded Lazily?

Path csiph.com!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail
From j4n bur53 <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: Are Outer Classes Loaded Lazily?
Date Thu, 21 Sep 2017 01:18:12 +0200
Organization albasani.net
Lines 55
Message-ID <opusvk$5se$1@news.albasani.net> (permalink)
References <opu86b$k29$1@news.albasani.net> <opunhc$c73$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net Pi/Ul4J2kVDXiHNr2ijkA/veFGjGbNjTRK9nx/zJj7Wd8rFJdQ3Tl9f7sG8MJSIe0brnsiB/4C5gBARLSh/wXg==
NNTP-Posting-Date Wed, 20 Sep 2017 23:18:12 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="+11Ohw/EaGTEkiu5hDKuGh0CozO7p1J/8udn8lg1USZY7nMBeu45QzqoBPZSvBRVoBLEIhPWWyZNOqfTnPbPPV+HjyIam/omYjR3Jivp50Nh57AzuW8OkhshK3DpJwUa"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:51.0) Gecko/20100101 Firefox/51.0 SeaMonkey/2.48
In-Reply-To <opunhc$c73$1@dont-email.me>
Cancel-Lock sha1:BmGVIT+zOlV6tyQkFwdE9a6LiIc=
Xref csiph.com comp.lang.java.programmer:37439

Show key headers only | 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