简体   繁体   中英

Why doesn't Java 8 allow interface members to be private?

While some have asked this question before , it was before Java 8 was released.

Previously, static members weren't allowed because implementation details were to not be defined in an interface. This was also why nothing should be private, because the implementer of the interface would need to provide implementation details.

This sort of changed with Java 8, didn't it? A default method defines implementation details, and so do static methods. Why, then, is this still not allowed?

Because of time constraints in the implementation.

Private methods were originally within spec, but in an email titled " Some Pullbacks ", sent by Brian Goetz to the lambda-spec-experts mailing list back when Java 8 was in development, they were pulled.

We would like to pull back two small features from the JSR-335 feature plan:

  • private methods in interfaces
  • "package modifier" for package-private visibility

The primary reason is resourcing ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM