By using the Java Reflection API, we can examine the details of a class—an object's class name, modifiers, constructors, methods, fields, implemented interfaces, and so on.
Let's assume that we have the following Pair class:
public final class Pair<L, R> extends Tuple implements Comparable {
final L left;
final R right;
public Pair(L left, R right) {
this.left = left;
this.right = right;
}
public class Entry<L, R> {}
...
}
Let's also assume that we have an instance of it:
Pair pair = new Pair(1, 1);
Now, let's use reflection to get the name of the Pair class.