开发者

How would one find out if a method is static using Java's reflection API?

If I didn't know that the sleep method on java.lang.Thread 开发者_StackOverflowwas static, how could I find out?


Use getModifiers on the Method object:

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


use

 (myclass.getModifiers() & Modifier.STATIC) != 0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜