Home > Back-end >  I the results of the field and deep understanding of "JVM" inconsistent results given in t
I the results of the field and deep understanding of "JVM" inconsistent results given in t

Time:12-03

,
 package chapter7. 

import java.io.IOException;
Import the Java. IO. InputStream;

/* *
* the description P280 listing 7-8
*
* @ author when
* @ the date 2020-12-02 20:51
* */
Public class ClassLoaderTest {
Public static void main (String [] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
This myLoader=new this () {
@ Override
Public Class<?> LoadClass (String name) throws ClassNotFoundException {
System. The out. Println (" MINE ");
The String fileName=name. The substring (name. LastIndexOf (". ") + 1) + ". Calss ";
InputStream is=getClass (). GetResourceAsStream (fileName);
If (is==null) {
Return super. LoadClass (name);
}
Try {
Byte [] b=new byte [is available ()];
Is. Read (b);
Return defineClass (name, b, 0, b.l ength);
} the catch (IOException e) {
Throw new ClassNotFoundException (name);
}
}
};

The Object obj=myLoader. LoadClass (" chapter7. ClassLoaderTest "). NewInstance ();
System. The out. Println (obj. GetClass ());
System. The out. Println (obj instanceof chapter7. ClassLoaderTest);
}
}


"Deep understanding of the Java virtual machine" in the third edition of P 281 listing 7-8 in addition to the package name, other all

The book says, the last line of output: false
But I use the output is: true

Excuse me why?
  • Related