What are tagging interfaces and what are they used for?
An interface without methods, fields and constants is known as marker or tagged interface. This type oi interface is an empty interface. It delivers runtime information about an object. This information is delivered to both the JVM and the compiler.
Examples of Tag Interfaces (from the Java API)Allows the state of an object to be converted to a byte stream in such a way that the byte stream can be reverted back into a copy of the object. A Java object is serializable if its class or any of its superclasses implements the java. io. Serializable interface.
In other words, an empty interface is known as marker interface or tag interface. It delivers the run-time type information about an object. It is the reason that the JVM and compiler have additional information about an object. The Serializable and Cloneable interfaces are the example of marker interface.
A Tag Interface is a Java term. It is an empty interface which a class implements to claim membership in a set. For example, if a class implements the Serializable interface, it is claiming to be serializable -- to be a member of the set of serializable classes.
A tagging interface typically has some magic associated with it: either directly built into the VM, or using reflection. Because the magic could technically apply to any class, you use the tagging to indicate that you thought well about the magic and whether it applies to your class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With