Explicit public on static interface methods?
andrey.breslav at jetbrains.com
Tue May 14 21:27:01 PDT 2013
> John Rose made this observation/suggestion:
> Implicit public considered risky: After working for a while on a new interface, I realized that all the methods I coded without an explicit "public" keyword were still public. I was using them as package privates shared between the interface and some package-private implementation logic. Oops. Did not discover this until I was preparing a javadoc for public review. That feels a little too late. Our processes would block me from accidentally introducing a public static, but that might not be true of customers.
> Suggest requiring a "public" on "static" interface members. Will reduce confusion if we allow non-public statics in the future.
Observation 1: We will never be able to have package-private members in interfaces, unless we require explicit public now.
Observation 2: Having static methods and fields inconsistently handled for interfaces looks ugly. Fields are public by default, so making methods package-private by default would look odd. (By observation 1, we can't have package-private fields in interfaces).
More information about the lambda-spec-experts