I'm not sure what you would like to do with an abstract static method in java, but the only potential use case that I saw in the past (I would like me to remember by whom ...) calls the method directly by a parameter of a general type.
i.e. if java allowed something like this ...
// this is not valid java... // let pretend we can define a static method in an interface interface Foo { static String Foo(); } // a class that implements our interface class FooImpl implements Foo { public static String Foo() {return "foo";} }
... we could use it for a generic parameter to call Foo () directly by type
static <T extends Foo> String Test() { return T.Foo();
This would make a little more sense in C #, because:
This basically means that in “pretend C #” with static interfaces you can use something that matches the above “pretend java” to write a generic method that works on any type that defines a particular operator (for example, everything what the Operator "+" has).
Now back to scala. How does scala address this script? This is partially not the case. scala has no static methods: the object is singleton (i.e. a class with only one instance), but still it is a class with the usual instance methods, that is, on objects that you still call on a single instance, and not directly on type (even operators are methods in scala).
So, in scala we will write:
trait Foo { def Foo:String } object FooImpl extends Foo { def Foo = "foo" } def Test(f: Foo) = f.Foo
... and call our method with
scala> Test(FooImpl) res0: String = foo
You can do some tricks with implicits to avoid passing a single instance as a parameter:
implicit def aFoo = FooImpl def Test2(implicit f: Foo) = f.Foo
now it works:
scala> Test2 res1: String = foo
With more advanced tricks with implicits, scala also defines Numeric, which allows operators to be used on any numerical value , even if they do not implement a common interface out of the box.