How to invoke a method using Method class in java

This example shows you use the Method class of java reflection API to invoke the method of class object. When using this method we need to catch for the NoSuchMethodException, IllegalAccessException and InvocationTargetException. Below is the example of invoking method using reflection. package com.java.connect.reflect; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; //How to invoke a method using Method […]

Continue reading


How to get constructors of an object in java using reflection

This example shows you how to get the number of constructors of an object using reflection in java. Below is an example that showing you how to get constructors of a class objects. In the code below we get the constructors by calling the Class.getDeclaredConstructors() or the Class.getConstructor(Class[]) method. package com.java.connect.reflect; import java.lang.reflect.Constructor; //How to […]

Continue reading