what difference does it make in a Java Interface to declare the method signature as final and non-final?
int setName(String name);
int setName(final String name);
what difference does it make in a Java Interface to declare the method signature as final and non-final?
int setName(String name);
int setName(final String name);
Section 8.4.1 of the Java Language specification allows the parameters in any method declaration (and that includes the ones in interfaces) to be declared final. However, since this does not influence the method's signature, declaring a parameter of an abstract function as final
has no effect. Since all methods in an interface are implicitely abstract, both variants are equivalent.
A couple of incidental differences
It can be used by the IDE as a hint. e.g. when you get the IDE to auto-generate your implemented methods, it will make the parameters final
by default in the same way it will re-use the same parameter names even though these are not part of the signature either.
the modifier final
is available via reflection and could be used by a framework for some implied purpose.