What is the marker/tagged interface in java?

An Interface that does not have any methods or variables inside is called the marker interface.

Example: Serializable, Cloneable, Remote are marker interfaces in java.

Java Code of marker interface is as shown:

Interface in Java

What is the functional interface in java?

The functional interface in java is an interface that has only one abstract method. This interface can contain static and default methods.

Example for the functional interface:

Interface in Java

Note that annotation @FunctionalInterface is not mandatory for the functional interface if it has only one abstract method. But it is suggested that we should add this annotation so if in the future if we try to add another abstract method in an interface it will give a compile-time error as shown.

Consumer, Function, Predicate are predefined functional interfaces in java. These are present in java.util.function package


What is the nested interface in java?

When an interface has another interface inside is called the nested interface. An example of a nested interface is shown below.


-A blog by Shwetali Khambe

Related Posts