From Java 8, in order for an interface to become functional, does it need to have just one method? But we have the @FuncionalInterface annotation, which explicitly defines that this interface is functional.
But what is the main difference in using this annotation or not, if with only one method it already becomes functional?
@FunctionalInterface
public interface FuncionalInterface <T>{
boolean valida(T t);
}
public interface FuncionalInterface <T>{
boolean valida(T t);
}
When printing the result is the same either with the annotation or without, look at the main:
public static void main(String[] args) {
FuncionalInterface<String> funcionalInterface = valor -> valor.matches("[0-9]{5}-[0-9]{3}");
System.out.println(funcionalInterface.valida("45680-000"));
}