How do I know if a method is static using the Java reflection API?

If I did not know that the method sleepon java.lang.Thread was static, how can I find out?

+3
source share
2 answers

Use getModifiersfor an object Method:

Method meth = ...;
if (Modifiers.isStatic(meth.getModifiers())) {
  // method is static
}
+7
source

use

 (myclass.getModifiers() & Modifier.STATIC) != 0
+1
source

Source: https://habr.com/ru/post/1773566/


All Articles