mercredi 13 juillet 2016

Why findLoadedClass method call is required in loadClass method?

As I was doing some experiment on class loading I wrote simple code like below.

    CustomClass customClass1 = new CustomClass();
    CustomClass customClass2 = new CustomClass();

And noticed that for the first instance creation it went to loadClass method and called the findLoadedClass method if it is already loaded by the current loader. It was not so it went ahead and loaded the class. But for second instance it did not go to loadClass method and directly created the instance of that.

So my question here is, when it was creating the second instance it already new that the class is already loaded so it did not go to loadClass method. So when jvm already now that which class is loaded and which is not then what is the need findLoadedClass method call inside loadClass method.

Aucun commentaire:

Enregistrer un commentaire