Explicit is something what is written in the source code. So, if something is declared as public final class
, it means that the class is explicitly final.
Implicit is something that is not written down in the source code, but that in the context of a certain construct or based on the language rules, an element behaves as it were declared with the specified modifier.
For example, the keyword enum
in the declaration enum SomeEnum { }
causes SomeEnum
to be final
, because the language rules prescribe it. Its effect is the same as the effect of the keyword final
.
The example of an anonymous class being implicitly final is because no language construct exists to override an anonymous class. So it behaves as if it were final
. I think the word "effectively" is better here.
However, you cannot make assumptions based on how reflection presents things. Consider the following snippet:
public class Test {
interface SomeInterface { }
abstract interface SomeAbstractInterface { }
static abstract class SomeAbstractClass { }
enum SomeEnum { }
public static void main(String arg[]) {
System.out.println(Modifier.toString(SomeInterface.class.getModifiers()));
System.out.println(Modifier.toString(SomeAbstractInterface.class.getModifiers()));
System.out.println(Modifier.toString(SomeAbstractClass.class.getModifiers()));
System.out.println(Modifier.toString(SomeEnum.class.getModifiers()));
}
}
The result is this:
abstract static interface
abstract static interface
abstract static
static final
Both interface
and abstract interface
are considered an abstract interface. They are also considered static by reflection. Apparently, in the process of parsing and compiling the Java source code, some modifiers could be removed or added.