2016-02-12 69 views

回答

1

显然,这根据lang spec存在于语言:

表达式E的注释表达式e, 由冒号分隔后出现。

所以这应该工作:

object TestAnnotation { 
    val o = Some(1) 

    def f = o.map(_ + 1 : @deprecated("gone", "forever")) 

    val e = { 1 + 2 } : @deprecated("hmm", "y") 

    println(f) 
    println(e) 
} 

然而,当我与scalac -deprecation编译我没有得到任何警告任何责任。我打开了一个问题here,得到了一个不支持的响应。你可以使用

一个解决办法是单独声明拉姆达:

object TestAnnotation { 
    val o = Some(1) 

    @deprecated("this", "works") val deprecatedLambda: Int => Int = _ + 1 

    o.map(deprecatedLambda) 
} 

scalac然后给出:

Annotation.scala:6: warning: value deprecatedLambda in object TestAnnotation is deprecated: this 
    o.map(deprecatedLambda) 
     ^
one warning found 
相关问题