• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Static methods in interfaces

Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Why don't interfaces support static final method declarations? I've been looking around, and I see plenty of explanations that just point to the JLS and say 'because'. Can anyone help me with why?
Abstract classes support static method declarations.
Interfaces support field declarations which are exposed as static final fields.
Static final methods in interfaces could be bound at compile time (like any other static method) and the compiler could complain about ambigous references (like it does with final static fields).
I'm not looking for a new JSR, but I searched and couldn't find an explanation. Any thoughts?
author and iconoclast
Posts: 24203
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debates about this have raged on the Internet since Java's earliest days. One page that summarizes the topic is http://zoom.z3950.org/bind/java/comment/static.html .
Basically, there could be static methods in interfaces, but the only sensible meaning for them would involve actually writing the code in the interface, not in any implementing classes. Static methods are looked up at compile time, not run time; there's no notion of "overriding" static methods.
If there were static methods in in interfaces, and they could be overridden by child classes, this would imply some fairly fundamental changes to the Java language and the JVM itself, and it's a little too late for that.
Your buns are mine! But you can have this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
    Bookmark Topic Watch Topic
  • New Topic