0

I am seeing that in the javadocs the accessibility specifier for Interface methods is not specified explicitly.

e.g. for interfaces Iterator or Comparable none of the methods have their accessibility modifier specified.

But for classes e.g. ArrayList the methods have their accessibility modifier specified. Why so ?

Ankur Agarwal
  • 23,692
  • 41
  • 137
  • 208

3 Answers3

1

That is because, the default access specifier for interface methods is public. However, for class it's package private - which won't be of much use for API classes.

Gurusharan S
  • 365
  • 1
  • 7
  • 1
    [This other SO question](http://stackoverflow.com/questions/161633/should-methods-in-a-java-interface-be-declared-with-or-without-a-public-access-m) talks about why it is not recommended as a good practice to specify the public access specifier for interface methods. – Gurusharan S Oct 05 '14 at 06:32
1

For interfaces all the methods are public and abstract as per java language specification. So there is no need to mention the access specifier if the above rule is true for all the interface methods.

But Classes can have different flavours of methods so access specifiers are mentioned for each method.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
1

In an interface, all methods implicitly have access public. An non-novice Java programmer would know this and understand this, and might consider that it was redundant to include a public access for methods in interface javadocs.

Other than that, the only explanation for the javadocs being formatted that way is that this is they way that the Oracle / Sun engineers decided to implement the javadoc generator. (They had to decide to include or omit the redundant modifiers, and they chose to omit them.) Frankly, it hardly matters which way they decided to implement this.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216