Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why interface methods are not static ?

 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
can anyone explain why the interface methods are not static .
As far as i understand interface methods are implemented in the implementation class . So the implementation class will be the one ultimately having the static method associated .
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static methods are not associated with a class. So an interface with a static method that no class can implement would be of no use.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ragi singh wrote:
As far as i understand interface methods are implemented in the implementation class . So the implementation class will be the one ultimately having the static method associated .

Then, could you expect the polymorphic behavior with that?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3752
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ragi singh wrote:Hi all,
can anyone explain why the interface methods are not static .

Interfaces do not support static methods because the language designers did not think it was a good or useful idea. Otherwise, there is no reason why an interface can't be designed to have declarations for static methods. Afterall, they do allow you to declare static fields.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may be confusing static with abstract.
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ragi Singh,

If interface methods are static, you cannot have polymorphic behavior in your implementation classes. To avoid that, interface methods cannot have static methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic