wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface" Watch "Interface" New topic
Author

Interface

Juva Yuva
Greenhorn

Joined: Dec 18, 2008
Posts: 17
Why Interface cannot have static fields and methods ? Any good reason behind it ?
Sunil Kumar
Ranch Hand

Joined: Apr 24, 2007
Posts: 76
Already discussed multiple times. Check here http://www.coderanch.com/t/410462/java/java/Static-Methods-Interface


Sunil Kumar
http://goodtoknowit.blogspot.com/
Sunil Kumar
Ranch Hand

Joined: Apr 24, 2007
Posts: 76
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

Joined: Jan 17, 2006
Posts: 1296
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.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
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.
 
subject: Interface