Getting a string that describes the class

Starting with JDK 8, we can obtain a quick description of a class (containing modifiers, name, types parameters, and so on) via the Class.toGenericString() method.

Let's take a look at several examples:

// public final class modern.challenge.Pair<L,R>
System.out.println("Description of Pair: "
+ clazz.toGenericString());

// public abstract interface java.lang.Runnable
System.out.println("Description of Runnable: "
+ Runnable.class.toGenericString());

// public abstract interface java.util.Map<K,V>
System.out.println("Description of Map: "
+ Map.class.toGenericString());
..................Content has been hidden....................

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