English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Marker interfaces are interfaces that do not declare any methods.
The most common use of extending an interface occurs when the parent interface does not contain any methods. For example, the MouseListener interface in the java.awt.event package extends java.util.EventListener, which is defined as-
package java.util; public interface EventListener{ }
Interfaces that do not have any methods are called marker interfaces. Marker interfaces have two basic design purposes.
Create a common parent object -Like the EventListener interface, this interface is extended by many other interfaces in the Java API, and you can create a common parent object among a set of interfaces using the marker interface. For example, when the interface extends EventListener, the JVM knows that this specific interface will be used in the event delegation scenario.
Add data types to the class -This is the origin of the term 'tag'. Classes that implement the marker interface do not need to define any methods (because the interface has no methods), but the class becomes an interface type through polymorphism.