Modifier public, private, protected, static, final, abstract
import java.lang.reflect.Modifier;
public class Main {
public static void main(String[] args) throws Exception {
getClassModifier(String.class);
getClassModifier(TestA.class);
getClassModifier(TestB.class);
}
private static void getClassModifier(Class clazz) {
int modifier = clazz.getModifiers();
if (Modifier.isPublic(modifier)) {
System.out.println(clazz.getName() + " class modifier is public");
}
if (Modifier.isPrivate(modifier)) {
System.out.println(clazz.getName() + " class modifier is private");
}
if (Modifier.isProtected(modifier)) {
System.out.println(clazz.getName() + " class modifier is protected");
}
if (Modifier.isStatic(modifier)) {
System.out.println(clazz.getName() + " class modifier is static");
}
if (Modifier.isFinal(modifier)) {
System.out.println(clazz.getName() + " class modifier is final");
}
if (Modifier.isAbstract(modifier)) {
System.out.println(clazz.getName() + " class modifier is abstract");
}
}
protected static final class TestA {
}
private abstract class TestB {
}
}
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.