I was wondering, is there an equivalent of python’s pass expression? The idea is to write method signatures without implementations and compiling them just to type-check those signatures for some library prototyping. I was able to kind of simulate such behavior using this:
def pass[A]:A = {throw new Exception("pass"); (new Object()).asInstanceOf[A]}
now when i write:
def foo():Int = bar()
def bar() = pass[Int]
it works(it typechecks but runtime explodes, which is fine), but my implementation doesn’t feel right (for example the usage of java.lang.Object()). Is there better way to simulate such behavior?
In Scala 2.10, there is the
???method in Predef.In 2.9, you can define your own one like this:
If you use this version without an explicit type paramter,
Awill be inferred to beNothing.