开发者

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

开发者 https://www.devze.com 2023-01-24 03:18 出处:网络
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:

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

精彩评论

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

关注公众号