September 2019
Intermediate to advanced
816 pages
18h 47m
English
The public methods of a class are accessible via the Class.getMethods() method. This method returns an array of Method:
Method[] methods = clazz.getMethods();// public boolean modern.challenge.Pair.equals(java.lang.Object)// public int modern.challenge.Pair.hashCode()// public int modern.challenge.Pair.compareTo(java.lang.Object)// ...System.out.println("Methods: " + Arrays.toString(methods));
For fetching the actual name of the methods, we can quickly provide a helper method:
public static List<String> getMethodNames(Method[] methods) { return Arrays.stream(methods) .map(Method::getName) .collect(Collectors.toList());}
Now, we only retrieve the names of the methods:
List<String> methodsName = getMethodNames(methods); ...