Modifier checker checks all possible modifiers for a method

 
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ModifierUtil {

  public static boolean isAbstract(Member member) {
    return Modifier.isAbstract(member.getModifiers());
  }

  public static boolean isAbstract(Class<?> clazz) {
    return Modifier.isAbstract(clazz.getModifiers());
  }

  public static boolean isFinal(Member member) {
    return Modifier.isFinal(member.getModifiers());
  }

  public static boolean isFinal(Class<?> clazz) {
    return Modifier.isFinal(clazz.getModifiers());
  }

  public static boolean isInterface(Member member) {
    return Modifier.isInterface(member.getModifiers());
  }

  public static boolean isInterface(Class<?> clazz) {
    return Modifier.isInterface(clazz.getModifiers());
  }

  public static boolean isNative(Member member) {
    return Modifier.isNative(member.getModifiers());
  }

  public static boolean isPrivate(Member member) {
    return Modifier.isPrivate(member.getModifiers());
  }

  public static boolean isPrivate(Class<?> clazz) {
    return Modifier.isPrivate(clazz.getModifiers());
  }

  public static boolean isProtected(Member member) {
    return Modifier.isProtected(member.getModifiers());
  }

  public static boolean isProtected(Class<?> clazz) {
    return Modifier.isProtected(clazz.getModifiers());
  }

  public static boolean isPublic(Member member) {
    return Modifier.isPublic(member.getModifiers());
  }

  public static boolean isPublic(Class<?> clazz) {
    return Modifier.isPublic(clazz.getModifiers());
  }

  public static boolean isStatic(Member member) {
    return Modifier.isStatic(member.getModifiers());
  }

  public static boolean isStatic(Class<?> clazz) {
    return Modifier.isStatic(clazz.getModifiers());
  }

  public static boolean isStrict(Member member) {
    return Modifier.isStrict(member.getModifiers());
  }

  public static boolean isSynchronized(Member member) {
    return Modifier.isSynchronized(member.getModifiers());
  }

  public static boolean isTransient(Member member) {
    return Modifier.isTransient(member.getModifiers());
  }

  public static boolean isVolatile(Member member) {
    return Modifier.isVolatile(member.getModifiers());
  }

  public static boolean isBridge(Member member) {
    if (member instanceof Method) {
      return Method.class.cast(member).isBridge();
    } else {
      return false;
    }
  }

  @SuppressWarnings("unchecked")
  public static boolean isVarArgs(Member member) {
    if (member instanceof Method) {
      return Method.class.cast(member).isVarArgs();
    } else if (member instanceof Constructor) {
      return Constructor.class.cast(member).isVarArgs();
    } else {
      return false;
    }
  }

  public static boolean isSynthetic(Member member) {

    return member.isSynthetic();
  }

  public static boolean isEnumConstant(Member member) {
    if (member instanceof Field) {
      return Field.class.cast(member).isEnumConstant();
    } else {
      return false;
    }
  }

}
  
Home 
  Java Book 
    Runnable examples  

Reflection Method:
  1. Convert method to property name
  2. Find a Method on the supplied class with the supplied name and no parameters
  3. Find a Method on the supplied class with the supplied name and parameter types
  4. Get all methods from a class
  5. Get constructor and its parameters and call constructor with parameter
  6. Get method by parameter type
  7. Get all declared methods from a class, not inherited
  8. Get specific method by its name and parameters
  9. Get Static Method
  10. Get the current running method name
  11. Invoke a method with Reflection
  12. Invoke a method on an object with parameters
  13. Invoke a method with 2 arguments
  14. Invoke private method
  15. Method modifiers: isSynthetic(), isVarArgs(), isBridge()
  16. Method return type, parameter's type
  17. Method signature
  18. Modifier public, private, protected, static, final, abstract
  19. Modifier checker checks all possible modifiers for a method
  20. Sort methods according to their name, number of parameters, and parameter types.