devxlogo

Determine the Characteristics of a Java Method

Determine the Characteristics of a Java Method

The java.lang.reflect defines a Method class that may be used to get information about a method in a Java class. Some of the main methods are:

 public native int getModifiers(); // e.g. public, private, staticpublic Class getReturnType(); // primitive or object typepublic Class getDeclaringClass (); // class that declares this Methodpublic String getName(); // string name of the methodpublic Class[] getParameterTypes(); // parameter types passed inpublic Class[] getExceptionTypes(); // exception types thrown// Invoke this Methodpublic native Object invoke(Object o, Object[] args)   throws IllegalAccessException, IllegalArgumentException,                        InvocationTargetException;

The first six methods listed here can provide all the details to determine the characteristics of a Java method. You can use these methods to obtain each of the elements that go in a method declaration. For example, a typical Java method will have this syntax:

 [modifiers]   (paramType1 param1, paramType2, param2,

See also  11 Effective Keyword Research Tools and Techniques
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist