September 2019
Intermediate to advanced
816 pages
18h 47m
English
By having an instance (an object) of Pair, we can find out the name of its class by calling the getClass() method, as well as Class.getName(), getSimpleName(), and getCanonicalName(), as shown in the following example:
Class<?> clazz = pair.getClass();// modern.challenge.PairSystem.out.println("Name: " + clazz.getName());// PairSystem.out.println("Simple name: " + clazz.getSimpleName());// modern.challenge.PairSystem.out.println("Canonical name: " + clazz.getCanonicalName());
Notice that getSimpleName() returns the unqualified class name. Alternatively, we can obtain the class as follows:
Class<Pair> clazz = Pair.class;Class<?> clazz ...