java.lang.reflect.Modifier.isStatic()でstaticメソッドを判定するサンプル

Javaコード:
package com.arkgame.study;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class StaticCondDemo {
public static final class ChangfaTu {
public static void funcA() {
System.out.println(“this is public static method “);

};

@SuppressWarnings(“unused")
private static void funcB() {
System.out.println(“this is static static method “);
};

public void funcC() {
System.out.println(“this is public Common method “);
};

@SuppressWarnings(“unused")
private void funcD() {
System.out.println(“this is private Common method “);
}

}

public static void main(String[] args) {

Method[] cftmd = ChangfaTu.class.getDeclaredMethods();

for (Method md : cftmd) {
if (Modifier.isStatic(md.getModifiers())) {
System.out.println(“staticメソッド:" + md.getName());
}
}
}

}

結果
staticメソッド:funcA
staticメソッド:funcB

Java

Posted by arkgame