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
Java Book
Runnable examples
Reflection Method:
- Convert method to property name
- Find a Method on the supplied class with the supplied name and no parameters
- Find a Method on the supplied class with the supplied name and parameter types
- Get all methods from a class
- Get constructor and its parameters and call constructor with parameter
- Get method by parameter type
- Get all declared methods from a class, not inherited
- Get specific method by its name and parameters
- Get Static Method
- Get the current running method name
- Invoke a method with Reflection
- Invoke a method on an object with parameters
- Invoke a method with 2 arguments
- Invoke private method
- Method modifiers: isSynthetic(), isVarArgs(), isBridge()
- Method return type, parameter's type
- Method signature
- Modifier public, private, protected, static, final, abstract
- Modifier checker checks all possible modifiers for a method
- Sort methods according to their name, number of parameters, and parameter types.