jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Why can't interfaces define a static method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why can Watch "Why can New topic

Why can't interfaces define a static method

Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1090
Why can't interfaces define static methods?
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
The simple answer to all such questions is "because the Java Language Specification says so".

In many such questions, it would be possible to imagine how the feature under discussion might have been allowed. The language designers had to make judgements about what features would be useful, understandable, easy to implement in compilers/JVMs, and encourage good programming. Static methods in interfaces would fall down on several of those criteria.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
Another answer is that they can. But such interfaces are called "abstract classes" and not "Interfaces" . Abstract classes and Interfaces are very similar in nature - they are both abstract (i.e. cannot be instantiated), and defines method signatures.

The difference is mainly that abstract classes can define method implementations as well - including static methods.

Entia non sunt multiplicanda praeter necessitatem
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
All methods in an interface are abstract. Static methods cannot be abstract, because they aren't polymorphic.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1090
Thanks to all of you for your replies. It was helpful.
I agree. Here's the link: http://aspose.com/file-tools
subject: Why can't interfaces define a static method
It's not a secret anymore!