getClass Class , , .
, , . , , , List, ;
static void foo(List l) {
System.out.println(l.getClass().getName());
}
:
foo(new LinkedList()); // Outputs "java.util.LinkedList"
foo(new ArrayList()); // Outputs "java.util.ArrayList"
foo List, (!) , , getClass , .
?
static synchronized Class, , . , foo notThreadSafe, , :
Foo.notThreadSafe();
Foo.notThreadSafe();
, notThreadSafe synchronized:
public static synchronized void notThreadSafe() {
}
public static void notThreadSafe() {
synchronized (Foo.class) {
}
}
(Foo.class Class foo.)
, 1 , 2 ( - Foo.class), .
; static synchronized (m1 m2), 1 m1, 2 m2, m2 m1, ( Class foo).
getClass()? Class - , getClass foo :
System.out.println(Foo.class == (new Foo()).getClass());