Stranger things in Android class resolution

I observe quite a few behaviors on Android (I'm working on a multidex problem, so I use the emulator in 4.4.4) that leave me speechless about loading the Android class:

In Android classes, classes should not be allowed when loaded by the class loader. But if I create a class:

public class M {
  public Foo m(String i) {
    switch (i) {
      case "0":
        return new Foo();
      case "1":
        return new Foo2();
    }
    return null;
  }
}

and debug my application by adding a clock:

getClass().getClassLoader().findLoadedClass("Foo")
getClass().getClassLoader().findLoadedClass("Foo2")

Then I see the download Mloading Fooand Foo2!

So the class allowed.

, , M extends Application, M . Foo Foo2 JVM, m(X), (Foo , X "0", Foo2 X="1").

- :

  • M , . M Foo at least Foo2.
  • , Application, -?
  • Android, -?
+4

Source: https://habr.com/ru/post/1649630/


All Articles