As I know, every class has a Class
object. There is one case when I use synchronize, for example:
public class A {
public static void main(String... args){
synchronize(A.class){
//do something...
}
}
}
This will lock A
's Class
object, right? When is this Class
object created? Is it created when the JVM loads the A
class or when I call A.class
? I can't find detail in JLS, could someone please provide the link about it?
this will lock A's Class object, right?
yes.
my question is when this Class object is created? is it created at JVM load A class or when i call A.class?
When the ClassLoader loads it, it returns a Class
object.
i can't find detail in JLS, could someone please provide the link about it, thanks.
I suggest reading the javadoc for the ClassLoader.loadClass()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With