Virtual Extension Methods in upcoming Java 8 release

前端 未结 5 738
既然无缘
既然无缘 2020-12-31 10:23

When I see code snippets like

  interface A {
      void a();
      void b() default { System.out.println(\"b\"); };
      void c() final { System.out.printl         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 10:50

    This is great because it allows you, the API writer to post-hoc extend interfaces without causing NoSuchMethodErrors. It also You provide default implementations for methods in V2 for classes compiled against V1; code works like a charm. This also allows you to override the default implementation in classes compiled against V2 as usual, and makes numbered interafces redundant. I consider it also superior than use-site extension methods.

提交回复
热议问题