I use Java but I have a better background with C#. I've been reading Java's default
and static
methods in interfaces. I think I understood how default methods in interfaces would be useful. For instance, we have extension methods in C#. One thing it helps language designers is that they could freely add new methods for interfaces such as Where
, Select
, etc. where lambda expressions can be used without breaking binary code compatibility. So default
methods in Java's interfaces can help in the same way.
But when it comes to static
methods in Java interfaces, it is where I am not sure how useful it would be. Can anyone explain me why static
methods added to interfaces and in what cases they are useful for us developers. I also would like to hear if there are different reasons for default
method other than what I mentioned.