You can find out if a method exists in Java using reflection.
Get the Class
object of the class you are interested in and call getMethod()
with the method name and parameter types on it.
If the method does not exist, it will throw a NoSuchMethodException
.
Also note that "functions" are called methods in Java.
And last but not least, keep in mind that if you think you need it, then there is a chance that you have design problems. Reflection (this is what the methods of checking actual Java classes are called) is a rather specialized Java function and should usually not be used in business code (although it was used quite widely with some good effects in some common libraries).
source share