相关疑难解决方法(0)

Scala 2.8中<:<,<%<和=:=的含义是什么?它们在哪里记录?

我可以在Predef的API文档中看到它们是泛型函数类型(From)=> To的子类,但就是这样.嗯什么?也许某处有文档,但搜索引擎不能很好地处理"<:<"之类的"名称",所以我无法找到它.

后续问题:我什么时候应该使用这些时髦的符号/类,为什么?

scala type-constraints scala-2.8

197
推荐指数
4
解决办法
3万
查看次数

NotNull特性如何在2.8中工作,是否有人真正使用它?

trait NotNull {}
Run Code Online (Sandbox Code Playgroud)

我一直试图看看这个特性如何保证某些东西不是空的我无法弄清楚:

def main(args: Array[String]) {
  val i = List(1, 2) 
  foo(i) //(*)
}

def foo(a: Any) = println(a.hashCode)

def foo(@NotNull a: Any) = println(a.hashCode) //compile error: trait NotNull is abstract

def foo(a: Any with NotNull) = println(a.hashCode) //compile error: type mismatch at (*)
Run Code Online (Sandbox Code Playgroud)

和:

val i = new Object with NotNull //compile-error illegal inheritance
Run Code Online (Sandbox Code Playgroud)

显然有一些特殊的编译器处理正在进行,因为它编译:

trait MyTrait {}

def main(args: Array[String]) {
  val i: MyTrait = null
  println(i)
}
Run Code Online (Sandbox Code Playgroud)

然而,这不是:

def main(args: Array[String]) {
  val i: NotNull …
Run Code Online (Sandbox Code Playgroud)

scala nullable scala-2.8

12
推荐指数
2
解决办法
2101
查看次数

标签 统计

scala ×2

scala-2.8 ×2

nullable ×1

type-constraints ×1