lundi 4 mai 2020

Is it possible to detect if class has nested classes to load them in Java?

If we have such Foo.java

class Foo {
    static class Bar {
    }
}

Then after compilation we will have Foo.class and Foo$Bar.class

Now if we have:

class Foo {

    static void bar() {
        Runnable r = new Runnable() {
            public void run() {};
        };
    }
}

Then we will have Foo.class and Foo$1.class.

As I understand if we manually load Foo.class then Foo$Bar.class or Foo$1.class are not loaded.

So, the question - if we have loaded Foo.class, can we understand if this class has some nested classes to load them (Foo$Bar.class and Foo$1.class in our example)? I mean can we understand what else we also should load.





Aucun commentaire:

Enregistrer un commentaire