tags:

views:

117

answers:

1
+2  A: 

I'll assume you're talking about Java since it's by far the most popular language that has interface types. It's probably because the designers of Java figured that interfaces are contracts and implementation doesn't belong in them. The general style of Java seems to favor strictness, i.e. disallowing things unless there's a very good reason to allow them instead of the other way around.

Static methods are really just free (C-style) functions anyhow, only more annoyingly verbose. The only reason why it matters what class you put them in is aesthetics/code organization. Therefore, not allowing them to be put in interfaces isn't a severe limitation.

dsimcha
+1 - very much along the lines of what I was going to say, only better. :) If you want a static method in a hierarchy of classes then try using an abstract base class rather than an interface (if this works?).
Will A
@Will: yes, this will work. I think it's an ugly design, but that's just subjective. You should keep one thing in mind, though, if you're adding static methods at different points in a class hierarchy: you can't override a static method, you can only shadow it. What this means: if X is the parent class of Y, and both of them have a public static method f(), then it can be hard to tell in some situations which version of f() you're actually calling.
Mike Baranczak