reflection - Detecting whether a method/function exists in Java -
is there method/function in java checks if method/function available function_exists(functionname)
in php?
here referring method/function of static class.
you can find out if method exists in java using reflection.
get class
object of class you're interested in , call getmethod()
method name , parameter types on it.
if method doesn't exist, throw nosuchmethodexception
.
also, please note "functions" called methods in java.
last not least: keep in mind if think need this, chances you've got design problem @ hand. reflection (which methods inspect actual java classes called) rather specialized feature of java , should not used in business code (although it's used quite heavily , nice effects in common libraries).
Comments
Post a Comment