2

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?

Community
  • 1
  • 1
Joseph Nields
  • 5,527
  • 2
  • 32
  • 48
  • In case anyone else was hoping the JLS would say why, [it doesn't](http://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.5). It just says you can't declare members `protected` or `private`. – T.J. Crowder Mar 30 '15 at 04:04

1 Answers1

7

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 ...

yshavit
  • 42,327
  • 7
  • 87
  • 124
  • 2
    I was *just typing* the comment "Unless someone can find a forum thread or something related to the JCP for adding default methods that says why..." and you posted this. :-) +1 – T.J. Crowder Mar 30 '15 at 04:07
  • 1
    @T.J.Crowder Yeah, ordinarily I would consider voting this as "primarily opinion-based," but in this case we actually the objective answer! I knew I had a reason for lurking on that list. ;) – yshavit Mar 30 '15 at 04:08
  • Looks like this is coming soon and looks like the default modifier for package visibility is on it's way out for Java 9? Thanks for the answer. – Joseph Nields Mar 30 '15 at 04:22
  • Support for private methods was recently added in the javac compiler. See [this email](http://mail.openjdk.java.net/pipermail/jdk9-dev/2015-March/001981.html). – aioobe Mar 31 '15 at 14:32