• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why interface methods are not static ?

 
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you may be confusing static with abstract.
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic