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


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

Re: Are Outer Classes Loaded Lazily?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Are Outer Classes Loaded Lazily?
Date 2017-09-20 17:45 -0400
Organization A noiseless patient Spider
Message-ID <opunhc$c73$1@dont-email.me> (permalink)
References <opu86b$k29$1@news.albasani.net>

Show all headers | View raw


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'.)

-- 
esosman@comcast-dot-net.invalid
Twelve hundred eighteen days to go.

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