Showing posts with label Reflection. Show all posts
How to check if a Java object is final
February 03, 2023
Java
Reflection
How to check if a Java object is finalfinal modifier can be applied at class level. If a Class is marked final it cannot be extended.
Sample final Class
final class MyCustomClass {
}Using java.lang.reflect.ModifierUsing java.lang.reflect.Modifier,, We can check if a class is final though java.lang.reflect.Modifier.isFinal() method.
MyCustomClass.class.getModifiers() will provide...