Starting with Java 8, default
methods were introduced into interfaces. Effectively, this means that not all methods in an interface
are abstract
.
Starting with Java 9 (maybe), private
methods will be allowed. This means that not all methods in an interface
are public abstract
.
The question "Should methods in a Java interface be declared with or without the public
access modifier?" was asked at Stack Overflow at https://stackoverflow.com/questions/161633/should-methods-in-a-java-interface-be-declared-with-or-without-a-public-access-m
There, most of the answers argued that public abstract
should not be used because no method in an interface
can be anything other than public abstract
. That is no longer the case.
So, in light of these new features of interfaces, should the public abstract
keywords be used in a Java interface method declaration?
In my specific environment, we will have people who are experienced software engineers, but not experienced in Java, reading Java code from time to time. I feel that leaving out the public abstract
keywords will now create an additional point of confusion for those not familiar with the history of how interfaces came to have different rules for using these keywords.
default
modifier or astatic
modifier is implicitlyabstract
... It is permitted, but discouraged as a matter of style, to redundantly specify theabstract
modifier for such a method declaration." Why do you expect that things should change?abstract
are becoming increasingly convoluted. In Java 9, that same sentence might be, "An interface method lacking adefault
modifier or astatic
modifier or aprivate
modifier is implicitly abstract..." Additionally, the auxiliary arguments for not explicitly using the keywords, namely, that all interface methods arepublic abstract
, are now moot.stream
tojava.util.Collection
, orMap.getOrDefault()
. Alternative is to create a new sub-interface, and get everyone to downcast, like Graphics2D, and nobody enjoyed that!