Why are interfaces in Java 8 allowed to have the main method?

Since Java 8, static methods are allowed in interfaces.

main() is a static method.

Hence, main() is allowed in interfaces.

We don’t need this, since it wasn’t allowed before, and yet we survived. But since static methods, by definition, are not bound to an instance of a class, but to the class itself, it makes sense to allow them in interfaces. It allows defining utility methods related to an interface (like the ones found in Collections, for example), in the interface itself, rather than a separate class).

There is no difference between class static methods and interface static methods.

Leave a Comment