Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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: 1294

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
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Is there a way to find out if a Method is static via reflection?
 
It's not a secret anymore!