Lakhyadeep Sen’s Post

Another small but interesting concept while studying interfaces was marker interfaces. Unlike normal interfaces, marker interfaces do not define any methods. Instead, they act as a signal to the Java runtime that a class has a certain capability. Things that became clear : • marker interfaces are empty interfaces without methods • they are used to "mark" a class so that the JVM treats it differently • they provide additional behaviour without forcing method implementation • some well-known examples in Java include Cloneable and Serializable • they are mainly used by libraries or the runtime to enable certain features A simple structure looks like this : interface IDemo { } class Test implements IDemo { } Here the interface itself does not contain any methods, but implementing it can allow a class to receive special handling in certain situations. Understanding marker interfaces showed another way Java uses interfaces beyond just defining behaviour. #java #oop #programming #learning #dsajourney

To view or add a comment, sign in

Explore content categories