Identifying instances using the marker pattern
This pattern is extremely useful in identifying instances at runtime for specific treatment, such as triggering the desired action when an instance is available.
Motivation
The marker interface pattern represents an empty interface. Such an interface is used to identify a special group of classes at runtime. Because of this fact, the maker pattern is sometimes called tagging, as its sole purpose is to distinguish a special type of instance. The application thus provides the possibility to use special handling for such cases at runtime. Logic can be separated and properly encapsulated. Because annotation represents a special form of interface, Java implements the marker interface in two ways – a class can inherit from an interface or be annotated.
Finding it in the JDK
A clearer example of using the marker interface in the JDK can be found in the java.base
module. The java.io
package defines the Serializable
interface...