Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic