Why does the interface not support the static method?

Possible duplicate:
Why can I declare static methods in an interface?

Inside the body of the interface, we cannot declare or define any static method. What is the reason? Can anyone answer this question?

+3
source share
1 answer

I assume you are talking about Java, as it is by far the most popular language that has types interface. Probably because the Java developers realized that the interfaces are in contracts, and the implementation is not included in them. The overall Java style seems to contribute to rigor, i.e. It prohibits broadcasting unless they have a good reason for allowing them, and not vice versa.

Static methods are actually just free (C-style) functions anyway, only more annoyingly verbose. The only reason it matters which class you put them in is the organization of aesthetics / code. Therefore, not allowing them to enter interfaces is not a serious limitation.

+2
source

Source: https://habr.com/ru/post/1761447/


All Articles