Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tagging Interfaces in Java

Tags:

java

interface

What are tagging interfaces and what are they used for?

like image 990
RubyDubee Avatar asked Aug 18 '09 10:08

RubyDubee


People also ask

What is the use of tagged interface?

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.

What are the properties of tagged interface in Java?

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.

What is tag and marker interface in Java example?

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.

Is tagged interface Serializable?

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.


1 Answers

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.

like image 104
Martin v. Löwis Avatar answered Oct 15 '22 02:10

Martin v. Löwis