I wouldn’t compare them in terms of pros/cons since they have different purposes and there’s seldom a “choice” to make between the two.
-
a.getClass()
returns the runtime type ofa
. I.e., if you haveA a = new B();
thena.getClass()
will return theB
class. -
A.class
evaluates to theA
class statically, and is used for other purposes often related to reflection.
In terms of performance, there may be a measurable difference, but I won’t say anything about it because in the end it is JVM and/or compiler dependent.
This post has been rewritten as an article here.