150. Inspecting classes

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.5.57