Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should methods in a Java interface be declared with or without a public access modifier?

Should methods in a Java interface be declared with or without the public access modifier?

Technically it doesn't matter, of course. A class method that implements an interface is always public. But what is a better convention?

Java itself is not consistent in this. See for instance Collection vs. Comparable, or Future vs. ScriptEngine.

like image 964
Benno Richters Avatar asked Oct 02 '08 10:10

Benno Richters


Video Answer


1 Answers

The JLS makes this clear:

It is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a method declared in an interface.

like image 114
Jon Skeet Avatar answered Sep 28 '22 06:09

Jon Skeet