2012-12-07 28 views
4

我想知道,是否有相当于python的pass表达式?这个想法是编写没有实现的方法签名,并编译它们只是为了对某些库原型的签名进行类型检查。我能种模拟使用本这样的行为:现在斯卡拉和Python的通行证

def pass[A]:A = {throw new Exception("pass"); (new Object()).asInstanceOf[A]} 

当我写:

def foo():Int = bar() 
def bar() = pass[Int] 

它的工作原理(这typechecks但运行时发生爆炸,这是很好的),但我的实现没有按”感觉不错(例如使用java.lang.Object())。有没有更好的方法来模拟这种行为?

回答

9

在斯卡拉2.10中,Predef有??? method

scala> ??? 
scala.NotImplementedError: an implementation is missing 
    at scala.Predef$.$qmark$qmark$qmark(Predef.scala:252) 
    ... 

在2.9,你可以定义自己的一个是这样的:

def ???[A]:A = throw new Exception("not implemented") 

如果你使用这个版本没有明确的类型参数,则A会被推断为Nothing

+6

???是史上最好的方法名称。 –