First, you have to create a new instance of your class:
Object o = clazz.newInstance();
Note: If your class does not have a default constructor, newInstance()
will throw an exception. In that case, you must query the appropriate constructor from your class and call it. This only makes sense, if you have some kind of convention, e.g. the constructor must accept exactly on String
argument or so (see Creating an instance using the class name and calling constructor). The easiest way is to require a default constructor, so the code above will work.
Then you can call any instance method of your object. Usually you should have another convention like the class must implement interface MyInterface
. This makes calling your method easy:
MyInterface myObj = (MyInterface)o;
myObj.checkUserFunc(argument);