4
We know that in an interface the methods do not have implementation, only signature, ie only the definition of their methods without the body, we conclude then that all are already methods Abstract, right? But then why are there statements like:
interface Exemplo {
void umMetodo();
abstract void outroMetodo();
}
class ImplementaExemplo implements Exemplo {
@Override
public void umMetodo() {
// TODO Auto-generated method stub
}
@Override
public void outroMetodo() {
// TODO Auto-generated method stub
}
}
What is the need of an abstract method in an interface? It would have relation exclusively to create the possibility of functional interface?
Functional interfaces should have the
abstract
in the signature? Omitting that then would be an escape from convention such as naming class with lowercase letter?– Jefferson Quesado
@Jeffersonquesado gave an upgrade, had mixed things up.
– Maniero
In the first position I ended up forgetting the Java 8, my fault, thanks for the alert.
– Emanoel
@Maniero but I’m still a little confused about the functional interface, in his phrase from the understanding that the interface must have only one method to be declared with a functional interface, correct? So whether the method is explicitly stated as abstract or not, is an interface with a single method a functional interface? Thank you
– Emanoel
Yes, it is considered, although not guaranteed. See: https://answall.com/q/11162/101
– Maniero
Because it is, very strange, in Java itself has the Consumer class ( you can check here: https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html ) even with the annotation @Functionalinterface that has more than one method.
– Emanoel
It only has an abstract method.
– Maniero
@Emanoel just ratifying what Maniero said:
andThen
has implementation default, leaving open only theaccept
, so only this method is abstract– Jefferson Quesado