File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface

 
Juva Yuva
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why Interface cannot have static fields and methods ? Any good reason behind it ?
 
Sunil Kumar
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already discussed multiple times. Check here http://www.coderanch.com/t/410462/java/java/Static-Methods-Interface
 
Sunil Kumar
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyways the answer is simple. "Where to define the implementation of the method". A static method is supposed to be a class level behaviour.

And more, we do have static fields in an Interface
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer is simpler than that. The reason that you can't define static methods in an interface is that the Java language specification doesn't allow it. There really is no other reason. When designing a language choices must be made about what is allowed and what isn't, and the designers of Java chose against this one. They could have chosen in favor and there would be very credible arguments for that position.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just noticed that the answer I gave was almost exactly the one given by EFH in the referenced thread. He says it better than I do so I'll defer to his answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic