What should default interfaces be for?

Lukas Eder lukas.eder at gmail.com
Tue Mar 13 03:33:46 PDT 2012


> I've come to the opposite opinion. That defaulted interfaces are a
> major new language feature in their own right, and should be
> celebrated as such. I want to use them as a new way of designing
> applications [...]

I can only agree with this. Personally, I'm not half as thrilled by
lambdas as by the fact that Java 8 will have extension methods, which
as an API designer are a much more powerful addition to the language /
JVM (this doesn't mean that I'm not thrilled by lambdas...)

I had recently brought up the possibility of supporting "final" as a
keyword for extension methods:
http://mail.openjdk.java.net/pipermail/lambda-dev/2011-December/004426.html

When I re-think about this, I really wonder whether there should be a
"default" keyword at all, or whether interface methods should be
declared like class methods:

interface A {
  // implicitly "public abstract"
  void a();
  // implicitly "public default"
  void b() { System.out.println("b"); }
  // implicitly "public", explicitly "final"
  final void c() { System.out.println("c"); }
}

Anyway, I understand that these features can be added after Java 8,
too. But the syntax employed in Java 8 should not prevent further
additions later on...

Cheers
Lukas


More information about the lambda-dev mailing list