Why we do need to write "implements FI" while implementing a FunctionalInterface?
@FunctionalInterface
interface FI
{
void sayHello(String name);
}
public class Hello implements FI
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
FI fi = (name) -> System.out.println("Hello " + name);
fi.sayHello("world");
}
}
The
@FunctionalInterface
is just a way to enforce a check from the compiler so that the annotated interface only has oneabstract
method, nothing more.In addition it's clearly stated that
So it's not even required to annotate it explicitly.
The annotated interface is still an interface and it's used as all other interfaces in Java code so you need to specifically specify when you are implementing it.
But being a functional interface allows you to define a lambda which overrides it directly: