Member-only story

Java8:- Interface and Functional Interface.

krishankant singhal
4 min readDec 15, 2019

--

Java8 is not new now. but it has brought lot of new functionality and changes which has made functional programming very easy. Today we are going to talk about the same. Changes which we are going to discuss about is

  1. default method in interface
  2. Static method in interface
  3. Functional interface

Default method in interface :- Interface is used to define abstract methods which can be implemented by derived classes. but we were not having capability of implementing method in interface itself , Mean Interface does not provide any way to provide default implementation of those abstract methods. With Advent of java8, now we can provide default implementation of a method in interface itself, which can be overridden if required. it help us to provide standard implementation of method with advantage of Interface.

Static method in interface :- With java8 you can implement the static method . the static method can be defined in the interface, but these methods cannot be overridden in Implementation Classes. To use a static method, Interface name should be instantiated with it, as it is a part of the Interface only.

public interface Interface1 {
void printName(String value);
default void testingDefaultMethod(String value)
{
System.out.println("Default Print and Class " + value);
}
static void testingStatic() {
System.out.println("testing Static Super method");
}
}

--

--

krishankant singhal
krishankant singhal

Written by krishankant singhal

Angular,Vuejs,Android,Java,Git developer. i am nerd who want to learn new technologies, goes in depth.

No responses yet