Sobes.tech
Junior — Middle

What does the term interface marker mean and how is it used in programming?

sobes.tech AI

Answer from AI

A marker interface is an interface without methods that serves to mark or identify a class as possessing a certain property or behavior. In Java, an example is the Serializable interface. Classes implementing such an interface signal to the system that they support certain functionality (for example, they can be serialized).

Using marker interfaces allows checking at runtime whether an object supports a certain characteristic without needing to add methods. This simplifies object handling and enables the use of special mechanisms (such as serialization, cloning).

Example:

public interface Serializable {}

public class User implements Serializable {
    private String name;
    // ...
}

// Check
if (obj instanceof Serializable) {
    // object can be serialized
}
What does the term interface marker mean and how is… - sobes.tech