File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Is there a way to find out if a Method is static via reflection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is there a way to find out if a Method is static via reflection?" Watch "Is there a way to find out if a Method is static via reflection?" New topic
Author

Is there a way to find out if a Method is static via reflection?

Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
I have a java.lang.reflection.Method passed to my method and I need to generate some text describing it. How do i find out if it's a static method?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi,

in class "java.lang.reflect.Method" there's a method getModifiers(). This method returns an int which you can in turn check with the static methods of class "java.lang.reflect.Modifier". The isStatic(int modifiers) will tell you wether a method is static or not

Marco
 
Consider Paul's rocket mass heater.
 
subject: Is there a way to find out if a Method is static via reflection?
 
Similar Threads
how declare a variable global ?
Modifiers
How to list all visible containers
Static method main calls non static constr
difference between redefining and overriding a method